JavaScript Close Menu On Click

By natem1270

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:

Source: Stack Overflow


Share it with your friends!

    Fatal error: Uncaught Exception: 12: REST API is deprecated for versions v2.1 and higher (12) thrown in /home/content/19/9652219/html/wp-content/plugins/seo-facebook-comments/facebook/base_facebook.php on line 1273