How to hide Twitter Bootstrap dropdown

后端 未结 24 2217
悲&欢浪女
悲&欢浪女 2020-12-13 03:37

This is getting annoying — when I click on an item in a Bootstrap dropdown, the dropdown doesn\'t close. I have it set up to open a Facebox lightbox when you click the dropd

相关标签:
24条回答
  • 2020-12-13 03:55

    Here is my solution on how to close the button dropdown and toggle the button :

    $(".btn-group.open", this)
        .trigger("click")
        .children("a.dropdown-toggle")
        .trigger("blur")
    

    Where "this" is a global container of the button group.

    0 讨论(0)
  • 2020-12-13 03:55

    The easist way:

      $('.navbar-collapse a').click(function(){
        $('.navbar-toggle').trigger('click')
      })
    
    0 讨论(0)
  • 2020-12-13 04:00

    Don't know if this will help anyone (maybe it is too specific to my case, and not to this question) but for me this worked:

    $('.input-group.open').removeClass('open');
    
    0 讨论(0)
  • 2020-12-13 04:03

    Try this:

    $('.dropdown.open .dropdown-toggle').dropdown('toggle');
    

    This may also work for you:

    $('[data-toggle="dropdown"]').parent().removeClass('open');
    
    0 讨论(0)
  • 2020-12-13 04:03

    It may have been added in retrospect (though, that feature is not documented, even in Bootstrap 4.3.1), but you can simply call it with a hide parameter. Just make sure to call it on the toggler element. Like so:

    $('.dropdown-toggle').dropdown('hide');
    // or
    $('[data-toggle="dropdown"]').dropdown('hide');
    

    Of course, this also works in reverse with show.

    0 讨论(0)
  • 2020-12-13 04:04

    Bootstrap 4.1:

    $(".dropdown-link").closest(".dropdown-menu").removeClass('show');
    
    0 讨论(0)
提交回复
热议问题