Home >Web Front-end >JS Tutorial >How to delete a class in javascript

How to delete a class in javascript

藏色散人
藏色散人Original
2021-07-12 11:50:244031browse

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.

How to delete a class in javascript

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!

Statement:
The 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.cn