为 <div>
元素添加 class:
document.getElementById(“myDIV”).classList.add(“mystyle”);
为 <div>
元素添加多个类:
document.getElementById(“myDIV”).classList.add(“mystyle”, “anotherClass”, “thirdClass”);
为 <div>
元素移除一个类:
document.getElementById(“myDIV”).classList.remove(“mystyle”);
为 <div>
元素移除多个类:
document.getElementById(“myDIV”).classList.remove(“mystyle”, “anotherClass”, “thirdClass”);
检查是否含有某个CSS类
myDiv.classList.contains(‘myCssClass’); //return true or false
原地址:https://blog.csdn.net/stone10086/article/details/78390353
原文地址:https://www.cnblogs.com/cailijuan/p/9360548.html
时间: 2024-11-13 11:00:09