为 <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
原创文章,作者:Maggie-Hunter,如若转载,请注明出处:https://blog.ytso.com/2165.html