I've been attempting to find a solution for closing the Bootstrap menu when clicking outside of it in a mobile window size, but I just can't seem to make it work. I did manage to get it working when clicking one of the 'a' links using this code:
// This code collapses the menu buttons when clicking a link
$('document').ready(function()
{
if ($('a').on('click', function()
{
$('.collapse, #mainContainer').removeClass('in');
$('.navbar-toggle').toggleClass('collapsed'); // button
}));
});
But how can I close the menu by clicking outside of the menu navbar?
Here's the link to my page where you can see the issue: iwebdesign.se
I have already tried the following, but it didn't work:
Similar question