Having a bit of an issue here. When I click on the menu button "x," it triggers an onclick event that opens/displays an element. All good so far. But now, I want to click the same menu button "x" to close that same element, and that's where I'm struggling. I'm not sure how to make it happen.
Here's my HTML code with the JS.
<a href="#" onclick="toggleSubMenu(); return false;" class="deco-text">services</a>
*toggleSubMenu means to turn the submenu on or off.
function toggleSubMenu() {
var menu = document.getElementById('menu-vg');
if(menu.style.display === "block") {
menu.style.display = "none";
} else {
menu.style.display = "block";
menu.style.zIndex = "999";
}
}
I tried adding another function after "return false" for closing, but it didn't work as expected.
Would greatly appreciate any help or advice. Thanks!
Ps. Before someone points out a similar question like this, I did search but couldn't find one. If there is, I'd appreciate a link to it.