I'm very new to JavaScript and having some trouble trying to get the desired result. I've built an off-canvas menu based on the w3 school's example. I want the user to be able to click the hamburger glyphicon to close the menu when it's open in addition to using the "x" button. If there is an easier way to do this using JQuery that would be great as well!
Here's my attempt:
var width = document.getElementById("nav").style.width;
while (width != 0) {
document.getElementById('glyphicon-menu-hamburger').onclick = closeNav();
}
Here's the codepen: https://codepen.io/nathanmathews/pen/XRKBBN
Here's my updated attempt, still incorrect:
var width = document.getElementById("nav").style.width;
if (width != 0) {
document.getElementById('glyphicon-menu-hamburger').onclick = closeNav;
}
()
. For more information, read these answers.while
loop condition doesn't make sense, because nothing inside the loop changes the value of thewidth
variable.