1

I want to close the re-sized menu when one clicks anywhere on the page. I've searched various stack overflow answers but haven't found one that does not interfere with the menu code itself, my menu...

jQuery(document).ready(function($) {
  //open-close submenu on mobile
  $('.cd-main-nav').on('click', function(event) {
    if ($(event.target).is('.cd-main-nav'))
      $(this).children('ul').toggleClass('is-visible0');
  });
  //i have tried adding this but hasn't worked
  $('html').click(function() {
    if ($('.cd-main-nav').children('ul').hasClass('is-visible0')) $(this).children('ul').toggleClass('is-visible0');

  });
});
Max Njoroge
  • 489
  • 3
  • 21

1 Answers1

1
$('html').click(function() {
     //Hide the menus if visible
});

Include this code as it detects click anywhere on the html page also to ensure the html doesnt fire when you click the element you intend to

$('.cd-main-nav').on('click', function(event) {
event.stopPropagation();
// rest of your code here
});
John
  • 114
  • 10