2021年1月3日星期日

how to remove a class with the onclick event with javascript

any way that when I press a button it shows me a class and when I press another it removes the other class from the first button and so on with the other buttons?

Thank you for your help

function myFunction() {      document.getElementById("active1").classList.add('MyClass');  }  function myFunction2() {       document.getElementById("active").classList.add('MyClass');  }  function myFunction3() {       document.getElementById("active2").classList.add('MyClass');  }
.MyClass {      background-color: red;      color: #00ff1f;  }
<html>  <body>  <div id="active1" class="none"><button onclick="myFunction()">Try it</button></div>    <div id="active" class="none"><button onclick="myFunction2()">forobeta</button></div>  <div id="active2" class="none"><button onclick="myFunction3()">femax</button></div>  <button   onclick="myFunction4()">forobeta</button>        </body>  </html>
https://stackoverflow.com/questions/65556434/how-to-remove-a-class-with-the-onclick-event-with-javascript January 04, 2021 at 08:42AM

没有评论:

发表评论