当前位置:网站首页>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 !
边栏推荐
- 409. longest palindrome
- [ta- frost wolf \u may- hundred people plan] 2.2 model and material space
- "Target detection" + "visual understanding" realizes the understanding of the input image
- Procurement intelligence is about to break out, and Alipay'3+2'system helps enterprises build core competitive advantages
- Unexpected token o in JSON at position 1, JSON parsing problem
- Web components series (VIII) -- custom component style settings
- Task04 mathematical statistics
- Note de développement du système embarqué 80: application du concepteur Qt à la conception de l'interface principale
- 创新界,聚势行 | 2022人大金仓“百城巡展”火热开启
- 定了!2022京东全球科技探索者大会之京东云峰会7月13日北京见
猜你喜欢
【TA-霜狼_may-《百人计划》】1.2.3 MVP矩阵运算
[TA frost wolf \u may- hundred talents plan] 1.2.3 MVP matrix operation
【发送邮件报错】535 Error:authentication failed
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
Mallbook: how can hotel enterprises break the situation in the post epidemic era?
【TA-霜狼_may-《百人计划》】2.2 模型与材质空间
Huawei simulator ENSP - hcip - Hybrid Experiment 2
After many job hopping, the monthly salary is equal to the annual salary of old colleagues
Custom components in applets
随机推荐
LeetCode 1828. Count the number of points in a circle
208. implement trie (prefix tree)
LeetCode 1380. Lucky number in matrix
Unity之三维空间多点箭头导航
[shortcut key]
Obtain detailed ideas for ABCDEF questions of 2022 American Games
使用WinMTR软件简单分析跟踪检测网络路由情况
Valid @suppresswarnings warning name
206.反转链表
TASK04|數理統計
72. edit distance
JMeter learning notes 2 - brief introduction to graphical interface
TASK04|数理统计
[ta - Frost Wolf May - 100 people plan] 1.2.1 base vectorielle
NFT: utilisez EIP - 2981 pour commencer un voyage de redevances NFT
分账技术赋能农贸市场,重塑交易管理服务效能
Note de développement du système embarqué 80: application du concepteur Qt à la conception de l'interface principale
"Target detection" + "visual understanding" realizes the understanding of the input image
小程序中自定义组件
Programs and processes, process management, foreground and background processes