How to delete a class in javascript

藏色散人
Release: 2021-07-12 11:50:24
Original
3914 people have browsed it

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.

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

element:

document.getElementById("myDIV").classList.add("mystyle");
Copy after login

Add multiple classes to

element:

document.getElementById("myDIV").classList.add("mystyle", "anotherClass", "thirdClass");
Copy after login

Remove a class for the

element:

document.getElementById("myDIV").classList.remove("mystyle");
Copy after login

Remove multiple classes for the

element:

document.getElementById("myDIV").classList.remove("mystyle", "anotherClass", "thirdClass");
Copy after login

Check whether it contains a certain CSS class

myDiv.classList.contains('myCssClass'); //return true or false
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!