Skip to content Skip to sidebar Skip to footer

Pop Out Navigation Menu To Close When Click Any Blank Part Of Page

My current project has a Navigation menu that has a floating toggle on the top left, and when toggled the menu pops out on the left hand side of the page. The menu auto closes whe

Solution 1:

There's a popular answer on this question here: How do I detect a click outside an element?

But it's important to look at the comments and the follow up article which suggest a much better option https://css-tricks.com/dangers-stopping-event-propagation/

$(document).on('click', function(event) {
    if (!$(event.target).closest('#theMenu').length) {
      $('#theMenu').removeClass('menu-open');
    }
});

Post a Comment for "Pop Out Navigation Menu To Close When Click Any Blank Part Of Page"