drop down menu auto collapse?

Hi, I have a one-page site with a menu on top. On mobile you can see the three lines to open the menu, but when you click one option it doesn't close so it cover a lot of the page, you have to close it manually. There is any way to auto-collapse the menu when i click a link?

My client is asking me for it.

Thank you!!

1 Like

@felo, you would need to create some JS that when you click the link in a mobile setting, it triggers the closing of the menu.

I think years back I created a quick little thing for someone so you may want to search for a similar article to find it.

Saj

thank you Saj. i will look for i it

//Hamburger menu toggle
  $(".navbar-nav li a").click(function (event) {
    var toggle = $(".navbar-collapse").hasClass("show");
    if (toggle) {
      $(".navbar-toggler").click();
    }
  });

  $('.navbar-nav > li > a').on('click', function() {
    $('.navbar-collapse').collapse('hide');
});

$('.navbar-nav>li>a').on('click', function(){
    $('.navbar-collapse').collapse('hide');
});

1 Like

thanks a lot. i use this post from Saj and it works fine! https://bootstrapstudio.io/forums/topic/collapsed-navbar-wont-close-with-same-page-anchors/

Thank you!

Glad I could help.

Saj