I'm building a sidenav menu. I want to work on the style directly in the css file instead of the Javascript code as below.
For example: dropContent.style.display === "block" and "none", I wish there was a class to modify and not add css values inside the js code. Is this possible ?
References: https://www.w3schools.com/howto/tryit.asp?filename=tryhow_js_sidenav_dropdown
var dropdown = document.getElementsByClassName("dropdown-btn");
var i;
for (i = 0; i < dropdown.length; i++) {
dropdown[i].addEventListener("click", function() {
this.classList.toggle("activate");
var dropContent = this.nextElementSibling;
if (dropContent.style.display === "block") {
dropContent.style.display = "none";
} else {
dropContent.style.display = "block";
}
});
}
classList.add('class-name')
? But I guess you wantclassList.toggle('class-name')
so you dont need an if/else-statement