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
element:document.getElementById("myDIV").classList.add("mystyle");Copy after loginAdd multiple classes to
element:document.getElementById("myDIV").classList.add("mystyle", "anotherClass", "thirdClass");Copy after loginRemove a class for the
element:document.getElementById("myDIV").classList.remove("mystyle");Copy after loginRemove multiple classes for the
element:document.getElementById("myDIV").classList.remove("mystyle", "anotherClass", "thirdClass");Copy after loginCheck whether it contains a certain CSS class
myDiv.classList.contains('myCssClass'); //return true or falseCopy after loginRecommended 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!
Related labels:source:php.cnPrevious article:How to use slice method in javascript Next article:What are the inheritance methods in javascriptStatement of this WebsiteThe content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cnLatest Articles by Author
2023-04-24 11:00:01 2023-04-24 10:55:51 2023-04-24 10:52:44 2023-04-23 17:40:51 2023-04-23 17:38:02 2023-04-23 17:34:02 2023-04-23 10:15:45 2023-04-23 10:10:52 2023-04-21 16:01:59 2023-04-21 15:58:01Latest Issues