当前位置:网站首页>2. Use of classlist (element class name)
2. Use of classlist (element class name)
2022-07-01 04:15:00 【superfortunate】
calssList attribute , Returns the class name of the element .
<style>
.bg {
background-color: black;
}
</style>
<div class="one two"></div>
<button> Turn on and off the lights </button>
<script>
// classList Returns the class name of the element
var div = document.querySelector('div');
// console.log(div.classList[1]);
// 1. Add class name Is to append the class name later, which will not overwrite the previous class name Note that the front does not need to be added .
div.classList.add('three');
// 2. Delete class name
div.classList.remove('one');
// 3. Switch classes
var btn = document.querySelector('button');
btn.addEventListener('click', function() {
document.body.classList.toggle('bg');
})
</script>Happy study !
边栏推荐
- Usage of AfxMessageBox and MessageBox
- [EI search] important information conference of the 6th International Conference on materials engineering and advanced manufacturing technology (meamt 2022) in 2022 website: www.meamt Org meeting time
- Valid @suppresswarnings warning name
- 什么是权限?什么是角色?什么是用户?
- [untitled] Li Kou 496 Next larger element I
- Unexpected token o in JSON at position 1, JSON parsing problem
- 分账技术赋能农贸市场,重塑交易管理服务效能
- JMeter login failure, extracting login token, and obtaining token problem solving
- Knowledge supplement: redis' basic data types and corresponding commands
- Edge浏览器的小技巧:Enter+Ctrl可以自动将地址栏转换为网址
猜你喜欢

程序员女友给我做了一个疲劳驾驶检测

NFT: start NFT royalty journey with eip-2981

JMeter login failure, extracting login token, and obtaining token problem solving
![[ta- frost wolf \u may- hundred people plan] 1.1 rendering pipeline](/img/af/4498382bc47d8c9ae41c407b9d1265.png)
[ta- frost wolf \u may- hundred people plan] 1.1 rendering pipeline

Jenkins自动清理构建历史

线程常用方法与守护线程
![[TA frost wolf \u may- hundred people plan] 1.2.1 vector basis](/img/94/99090ea91082a385968e071ef3766c.png)
[TA frost wolf \u may- hundred people plan] 1.2.1 vector basis

Why can't you find the corresponding function by clicking go to definiton (super easy has a diagram)

NFT: utilisez EIP - 2981 pour commencer un voyage de redevances NFT

Hololens2 development environment building and deploying apps
随机推荐
有效的 @SuppressWarnings 警告名称
Common thread methods and daemon threads
Valid @suppresswarnings warning name
Obtain detailed ideas for ABCDEF questions of 2022 American Games
[human version] Web3 privacy game in the dark forest
类和对象收尾
使用WinMTR软件简单分析跟踪检测网络路由情况
ThreeJS开篇
[ta - Frost Wolf May - 100 people plan] 1.2.1 base vectorielle
[send email with error] 535 error:authentication failed
Note de développement du système embarqué 80: application du concepteur Qt à la conception de l'interface principale
241. Design priorities for operational expressions
Programs and processes, process management, foreground and background processes
[JPCs publication] the Third International Conference on control theory and application in 2022 (icocta 2022)
盘点华为云GaussDB(for Redis)六大秒级能力
In the innovation community, the "100 cities Tour" of the gold warehouse of the National People's Congress of 2022 was launched
【深度学习】(4) Transformer 中的 Decoder 机制,附Pytorch完整代码
Network metering - application layer
小程序中自定义组件
网站服务器:好用的网站服务器怎么选这五方面要关注