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

How to delete class in javascript

王林
Release: 2021-11-01 17:15:19
Original
5210 people have browsed it

Javascript method to delete class: [var btn=document.querySelector(".btn1");btn.onclick=function(){ this.classList.remove("btn2")}].

How to delete class in javascript

#The operating environment of this article: windows10 system, javascript 1.8.5, thinkpad t480 computer.

Javascript method to add class:

obj.classList.add("active");
Copy after login

javascript method to delete class:

obj.classList.remove("active");
Copy after login

Example:

<button class="btn1 btn2">点击</button>
        <script>
            var btn=document.querySelector(".btn1");
            btn.onclick=function(){
                this.classList.remove("btn2")
            }
</script>
Copy after login

Recommended learning: javascript video tutorial

The above is the detailed content of How to delete 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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template