当前位置:网站首页>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 79: why should I get the IP address of the local network card
- Ospfb notes - five messages [ultra detailed] [Hello message, DD message, LSR message, LSU message, lsack message]
- 283. move zero
- 嵌入式系统开发笔记80:应用Qt Designer进行主界面设计
- Browser top loading (from Zhihu)
- MallBook:后疫情时代下,酒店企业如何破局?
- Knowledge supplement: redis' basic data types and corresponding commands
- Introduction of Spock unit test framework and its practice in meituan optimization___ Chapter I
- 互联网行业最佳产品开发流程 推荐!
- Codeforces Round #721 (Div. 2)B1. Palindrome Game (easy version)B2. Palindrome game (hard version)
猜你喜欢
【历史上的今天】6 月 30 日:冯·诺依曼发表第一份草案;九十年代末的半导体大战;CBS 收购 CNET

DO280管理应用部署--RC

类和对象收尾

Do280 management application deployment --rc

NFT:使用 EIP-2981 開啟 NFT 版稅之旅

Inventory the six second level capabilities of Huawei cloud gaussdb (for redis)
![[ta - Frost Wolf May - 100 people plan] 1.2.1 base vectorielle](/img/94/99090ea91082a385968e071ef3766c.png)
[ta - Frost Wolf May - 100 people plan] 1.2.1 base vectorielle

TS type gymnastics: illustrating a complex advanced type

Programs and processes, process management, foreground and background processes

京东智能客服言犀意图体系搭建和意图识别技术介绍
随机推荐
js 图片路径转换base64格式
使用scroll-view实现滑块视图可能遇到的问题及其解决方法
LeetCode 1399. Count the maximum number of groups
All in one 1086: Jiaogu conjecture
Codeforces Round #721 (Div. 2)B1. Palindrome Game (easy version)B2. Palindrome game (hard version)
Usage of AfxMessageBox and MessageBox
[today in history] June 30: von Neumann published the first draft; The semiconductor war in the late 1990s; CBS acquires CNET
Edge浏览器的小技巧:Enter+Ctrl可以自动将地址栏转换为网址
嵌入式系统开发笔记81:使用Dialog组件设计提示对话框
Do280 management application deployment --rc
网站服务器:好用的网站服务器怎么选这五方面要关注
409. longest palindrome
Volley parsing data shows networking failure
208. implement trie (prefix tree)
TASK04|数理统计
25.K个一组翻转链表
OSPF notes [multiple access, two multicast addresses with OSPF]
高并发下接口幂等性如何保证?
[untitled] Li Kou 496 Next larger element I
【深度学习】(4) Transformer 中的 Decoder 机制,附Pytorch完整代码