0

I was trying to solve an issue where when I clicked on a navbar menu item in mobile view the navbar remained expanded. this didn't work for me as my menu item was pointing to a div ID. I read here of a solution to add the below to my a href tag.

data-toggle="collapse" data-target=".navbar-collapse" 

this did not work for me but I could get it to work using a javascript fix I found on github https://github.com/twbs/bootstrap/issues/12852

$(document).on('click','.navbar-collapse.in',function(e) {
if( $(e.target).is('a') ) {
    $(this).collapse('hide');
}
});

Now the problem is that after the navbar was hidden I could not open it a second time.

Anyone else have this problem or a solution?

Torads
  • 69
  • 1
  • 10

1 Answers1

0

Change the collapse parameter from hide to toggle.

$(this).collapse('toggle');

See more at bootstrap docs.

Kami
  • 19,134
  • 4
  • 51
  • 63