Close responsive navbar automatically

前端 未结 12 1660
天命终不由人
天命终不由人 2020-12-05 02:04

I\'m using a Bootstrap responsive navbar. When the navbar is collapsed and I open the menu and click on a menu item, the menu doesn\'t close automatically, and I have to do

12条回答
  •  独厮守ぢ
    2020-12-05 02:55

    Only thing I'd add to jason's solution is the exception for dropdowns. You don't want to close your menu if someone is simply clicking to toggle the submenu. So…

    $('.navbar-collapse a:not(.dropdown-toggle)').click(function(){
        $(".navbar-collapse").collapse('hide');
    });
    

提交回复
热议问题