当前位置:网站首页>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 !
边栏推荐
- Account sharing technology enables the farmers' market and reshapes the efficiency of transaction management services
- Jenkins automatically cleans up construction history
- LeetCode 1380. Lucky number in matrix
- LetCode 1829. Maximum XOR value per query
- Concurrent mode of different performance testing tools
- [EI conference] the Third International Conference on nanomaterials and nanotechnology in 2022 (nanomt 2022)
- PageObject模式解析及案例
- [untitled] Li Kou 496 Next larger element I
- 高并发下接口幂等性如何保证?
- Unexpected token o in JSON at position 1, JSON parsing problem
猜你喜欢

Recommend the best product development process in the Internet industry!

Knowledge supplement: basic usage of redis based on docker

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

这可能是你进腾讯最后的机会了..

js 图片路径转换base64格式

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

TASK04|数理统计

Tip of edge browser: enter+ctrl can automatically convert the address bar into a web address

【TA-霜狼_may-《百人计划》】1.1 渲染流水线

基于Unet的环路滤波
随机推荐
283.移动零
小程序中自定义组件
为什么香港服务器最适合海外建站使用
使用scroll-view实现滑块视图可能遇到的问题及其解决方法
嵌入式系统开发笔记79:为什么要获取本机网卡IP地址
25.K个一组翻转链表
Use of JMeter counters
【历史上的今天】6 月 30 日:冯·诺依曼发表第一份草案;九十年代末的半导体大战;CBS 收购 CNET
674. longest continuous increasing sequence force buckle JS
做网站数据采集,怎么选择合适的服务器呢?
Use selenium automated test tool to climb the enrollment score line and ranking of colleges and universities related to the college entrance examination
Jenkins automatically cleans up construction history
431. encode n-ary tree as binary tree DFS
What is uid? What is auth? What is a verifier?
Edge浏览器的小技巧:Enter+Ctrl可以自动将地址栏转换为网址
这可能是你进腾讯最后的机会了..
Obtain detailed ideas for ABCDEF questions of 2022 American Games
[TA frost wolf \u may- hundred people plan] 1.2.1 vector basis
Some small knowledge points
【TA-霜狼_may-《百人计划》】2.2 模型与材质空间