I want for people to hide/show nav
when they click "Menu". Here is my code:
<script>
document.querySelector(".switch").onclick = function() {
if (document.querySelector(".mobileNav ul").className == "drop"){
this.className = "dropShow";
}
else {
this.className = "drop";
}
};
</script>
but it doesn't do anything.
Almost there. Just a minor error.
this.className assigns the className to the button element with class .switch . Instead do the following:
document.querySelector(".switch").onclick = function() {
var ulElem = document.querySelector(".mobileNav ul");
if ( ulElem.className== "drop"){
ulElem.className = "dropShow";
}
else {
ulElem.className = "drop";
}
};
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.