3

My Bootstrap 3 mobile menu does collapse when I click/touch outside the menu.

Ive can up with a solution to the problem:

$(document).on('touchstart click', 'html:not(nav)',function() {
 $(".navbar-collapse").removeClass("in");
});

However this doesn't collapse the same way as if you were to click the menu button. Please can somebody recommend a better solution.

Cheers Al

1 Answers1

5
$(document).on('click',function(){
  $('.navbar-collapse').collapse('hide');
})

Demo

Zac
  • 984
  • 14
  • 25
  • Will this work on mobile (iphone)? I think we need touchstart as well. – Marek May 07 '18 at 08:19
  • @Marek yes you might need to do `'click touch'` or `'click touchstart'` to make it behave as you need on iOS (I'm unable to test this though) – Zac May 08 '18 at 16:14