Javascript method to delete a class: 1. Remove a class from the
element through the "remove("mystyle")" method; 2. Use "remove("mystyle", "anotherClass", " The thirdClass");" method removes multiple classes.
The operating environment of this article: windows7 system, javascript version 1.8.5, DELL G3 computer
How to delete a class with javascript?
Native JS add class, delete class
Add class to
document.getElementById("myDIV").classList.add("mystyle");
Add multiple classes to
document.getElementById("myDIV").classList.add("mystyle", "anotherClass", "thirdClass");
Remove a class for the
document.getElementById("myDIV").classList.remove("mystyle");
Remove multiple classes for the
document.getElementById("myDIV").classList.remove("mystyle", "anotherClass", "thirdClass");
Check whether it contains a certain CSS class
myDiv.classList.contains('myCssClass'); //return true or false
Recommended study: "javascript Advanced Tutorial"
The above is the detailed content of How to delete a class in javascript. For more information, please follow other related articles on the PHP Chinese website!