原生js添加类名删除类名
为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
兼容性Ie10以上