当前位置:网站首页>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 !
边栏推荐
- Embedded System Development Notes 80: using QT designer to design the main interface
- 创新界,聚势行 | 2022人大金仓“百城巡展”火热开启
- 431. 将 N 叉树编码为二叉树 DFS
- Jenkins automatically cleans up construction history
- PageObject模式解析及案例
- JMeter学习笔记2-图形界面简单介绍
- DO280管理应用部署--RC
- 不同性能测试工具的并发模式
- 206. reverse linked list
- What does ft mean in the data book table
猜你喜欢

【发送邮件报错】535 Error:authentication failed

js 图片路径转换base64格式

Use of JMeter counters
![[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

JMeter learning notes 2 - brief introduction to graphical interface

After many job hopping, the monthly salary is equal to the annual salary of old colleagues

Task04 | statistiques mathématiques

JD intelligent customer service Yanxi intention system construction and intention recognition technology introduction

“目标检测“+“视觉理解“实现对输入图像的理解

Jenkins automatically cleans up construction history
随机推荐
10. regular expression matching
Grid system in bootstrap
Analysis and case of pageobject mode
431. 将 N 叉树编码为二叉树 DFS
Programs and processes, process management, foreground and background processes
Task04 | statistiques mathématiques
[EI conference] the Third International Conference on nanomaterials and nanotechnology in 2022 (nanomt 2022)
MySQL function variable stored procedure
Do280 management application deployment --rc
[today in history] June 30: von Neumann published the first draft; The semiconductor war in the late 1990s; CBS acquires CNET
跳槽一次涨8k,5年跳了3次...
Procurement intelligence is about to break out, and Alipay'3+2'system helps enterprises build core competitive advantages
[untitled] Li Kou 496 Next larger element I
Common thread methods and daemon threads
It's settled! 2022 JD cloud summit of JD global technology Explorer conference see you in Beijing on July 13
One job hopping up 8K, three times in five years
Concurrent mode of different performance testing tools
206.反转链表
[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
[EI conference] 2022 international joint civil and Offshore Engineering Conference (jccme 2022)