how to use toggle in javascript code example
Example 1: classname toggle js
document.getElementById('myButton').onclick = function() {
this.classList.toggle('active');
}
Example 2: toggle class to an element javascript
function toggleClass(){
var element = document.getElementById("addActive");
if (element.classList) {
element.classList.toggle("active");
} else {
var classes = element.className.split(" ");
var i = classes.indexOf("active");
}
}
Example 3: toggle element javascript
document.querySelector("#test").hidden = true;
document.querySelector("#test").hidden = false;