当前位置:网站首页>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 !
边栏推荐
- 【无标题】
- Web components series (VIII) -- custom component style settings
- 熊市下的Coinbase:亏损、裁员、股价暴跌
- Procurement intelligence is about to break out, and Alipay'3+2'system helps enterprises build core competitive advantages
- In the innovation community, the "100 cities Tour" of the gold warehouse of the National People's Congress of 2022 was launched
- Valid @suppresswarnings warning name
- Unity之三维空间多点箭头导航
- Edge浏览器的小技巧:Enter+Ctrl可以自动将地址栏转换为网址
- Deep learning | rnn/lstm of naturallanguageprocessing
- 高并发下接口幂等性如何保证?
猜你喜欢

Quickly filter data such as clock in time and date: Excel filter to find whether a certain time point is within a certain time period

熊市下的Coinbase:亏损、裁员、股价暴跌

【TA-霜狼_may-《百人计划》】2.2 模型与材质空间
![[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

【人话版】WEB3黑暗森林中的隐私博弈

【TA-霜狼_may-《百人计划》】1.2.1 向量基础

Procurement intelligence is about to break out, and Alipay'3+2'system helps enterprises build core competitive advantages

431. encode n-ary tree as binary tree DFS

Edge浏览器的小技巧:Enter+Ctrl可以自动将地址栏转换为网址

Unexpected token o in JSON at position 1, JSON parsing problem
随机推荐
嵌入式系统开发笔记80:应用Qt Designer进行主界面设计
Unity之三维空间多点箭头导航
NFT: utilisez EIP - 2981 pour commencer un voyage de redevances NFT
跳槽一次涨8k,5年跳了3次...
Possible problems and solutions of using scroll view to implement slider view
Redis(七)优化建议
Visit the image URL stored by Alibaba cloud to preview the thumbnail directly on the web page instead of downloading it directly
TASK04|數理統計
Grid system in bootstrap
What is uid? What is auth? What is a verifier?
[ta- frost wolf \u may- hundred people plan] 1.1 rendering pipeline
创新界,聚势行 | 2022人大金仓“百城巡展”火热开启
PageObject模式解析及案例
互联网行业最佳产品开发流程 推荐!
有效的 @SuppressWarnings 警告名称
Redis (VII) optimization suggestions
Valid @suppresswarnings warning name
What does ft mean in the data book table
TCP/IP 详解(第 2 版) 笔记 / 3 链路层 / 3.4 桥接器与交换机 / 3.4.2 多属性注册协议(Multiple Registration Protocol (MRP))
283.移动零