Home > Article > Web Front-end > How to delete a class in javascript
Javascript method to delete a class: 1. Remove a class from the dc6dce4a544fdca2df29d5ac0ea9906b 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 dc6dce4a544fdca2df29d5ac0ea9906b element:
document.getElementById("myDIV").classList.add("mystyle");
Add multiple classes to dc6dce4a544fdca2df29d5ac0ea9906b element:
document.getElementById("myDIV").classList.add("mystyle", "anotherClass", "thirdClass");
Remove a class for the dc6dce4a544fdca2df29d5ac0ea9906b element:
document.getElementById("myDIV").classList.remove("mystyle");
Remove multiple classes for the dc6dce4a544fdca2df29d5ac0ea9906b element:
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!