当前位置:网站首页>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 !
边栏推荐
- [untitled]
- 互联网行业最佳产品开发流程 推荐!
- Deep learning | rnn/lstm of naturallanguageprocessing
- Ospfb notes - five messages [ultra detailed] [Hello message, DD message, LSR message, LSU message, lsack message]
- 多次跳槽后,月薪等于老同事的年薪
- [JPCs publication] the Third International Conference on control theory and application in 2022 (icocta 2022)
- 什么是权限?什么是角色?什么是用户?
- In the innovation community, the "100 cities Tour" of the gold warehouse of the National People's Congress of 2022 was launched
- [TA frost wolf \u may- hundred talents plan] 1.2.3 MVP matrix operation
- Qt开发经验小技巧226-230
猜你喜欢

Network metering - application layer
![[TA frost wolf \u may- hundred talents plan] 1.2.3 MVP matrix operation](/img/4e/8cf60bc816441967c04f97c64685a1.png)
[TA frost wolf \u may- hundred talents plan] 1.2.3 MVP matrix operation

TASK04|數理統計

创新界,聚势行 | 2022人大金仓“百城巡展”火热开启

25.K个一组翻转链表

Jenkins自动清理构建历史

TS type gymnastics: illustrating a complex advanced type

One job hopping up 8K, three times in five years

js 图片路径转换base64格式

Account sharing technology enables the farmers' market and reshapes the efficiency of transaction management services
随机推荐
318. Maximum word length product
[ta- frost wolf \u may- hundred people plan] 2.2 model and material space
LeetCode 1380. Lucky number in matrix
TASK04|數理統計
[ta- frost wolf \u may- hundred people plan] 1.1 rendering pipeline
盘点华为云GaussDB(for Redis)六大秒级能力
Loop filtering based on Unet
In the innovation community, the "100 cities Tour" of the gold warehouse of the National People's Congress of 2022 was launched
LeetCode 1828. Count the number of points in a circle
采购数智化爆发在即,支出宝'3+2'体系助力企业打造核心竞争优势
Leetcode learning - day 36
25.k sets of flipped linked lists
线程常用方法与守护线程
This may be your last chance to join Tencent
208. implement trie (prefix tree)
DO280管理应用部署--RC
Programs and processes, process management, foreground and background processes
js 图片路径转换base64格式
Use winmtr software to simply analyze, track and detect network routing
Valid @suppresswarnings warning name