Answers for "classname toggle js"

0

classname toggle js

document.getElementById('myButton').onclick = function() {
    this.classList.toggle('active');
}
Posted by: Guest on July-29-2020
17

toggle css class in javascript

/* var or const followed by its name */.getElementById(/* HTML element ID */);
/* var or const's name */.classList.toggle(/* Name of CSS class */);
// I hope this helps!
Posted by: Guest on June-25-2020
-2

classname toggle js

document.getElementById('myButton').onclick = function() {

    var className = ' ' + myButton.className + ' ';

    if ( ~className.indexOf(' active ') ) {
        this.className = className.replace(' active ', ' ');
    } else {
        this.className += ' active';
    }              
}
Posted by: Guest on July-29-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language