Javascript method to delete class: [var btn=document.querySelector(".btn1");btn.onclick=function(){ this.classList.remove("btn2")}].
#The operating environment of this article: windows10 system, javascript 1.8.5, thinkpad t480 computer.
Javascript method to add class:
obj.classList.add("active");
javascript method to delete class:
obj.classList.remove("active");
Example:
<button class="btn1 btn2">点击</button> <script> var btn=document.querySelector(".btn1"); btn.onclick=function(){ this.classList.remove("btn2") } </script>
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!