const hamburgerMenuBtn = document.getElementById("hamburger-menu-button");
hamburgerMenuBtn.addEventListener("click", function() {
hamburgerPopupToggle()
});
function hamburgerPopupToggle() {
console.log("Button pressed");
const hamburgerMenuPopup = document.getElementById("hamburger-menu-popup");
if (hamburgerMenuPopup.style.display === "block") {
hamburgerMenuPopup.style.display = "none";
console.log(hamburgerMenuPopup.style.display);
} else {
hamburgerMenuPopup.style.display = "block";
console.log(hamburgerMenuPopup.style.display);
}
}
#hamburger-menu-popup { display: none; }
<div class="hamburger-menu">
<span id="hamburger-menu-button">menu</span>
<div id="hamburger-menu-popup">
<div id="home-button">Home</div>
<div id="create-post">Create a Post</div>
</div>
</div>
The popup opens
(https://i.sstatic.net/4hlVl4VL.png)
But then instead of setting display style back to "none", it sets it to "unset !important", BUT it logs that it’s "none" (https://i.sstatic.net/DadeuwQ4.png)(https://i.sstatic.net/bmL9RzHU.png)
So, for some reason it logs what was supposed to happen, but the CSS doesn’t change whatsoever. (It changes, but not as expected)
2
Answers
Please try like this :
Your code works fine for me, so there’s probably something else causing the issue for you (some plugin probably?).
I recommend just toggling a class on your menu-element. This has two advantages:
JS:
CSS: