How to hide Twitter Bootstrap dropdown

后端 未结 24 2215
悲&欢浪女
悲&欢浪女 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:48

    Try this!

    .removeClass("open").trigger("hide.bs.dropdown").trigger("hidden.bs.dropdown");
    

    OR

    $(clicked_element).trigger("click");
    

    It always work for me.

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

    Reading the documentation and using JavaScript it could be done using the toggle method:

    $('.button-class').on('click',function(e) {
        e.preventDefault();
        $('.dropdown-class').dropdown('toggle');
    }
    

    You can read about it in: http://getbootstrap.com/javascript/#dropdowns-methods

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

    The easiest way to do this is: you add a hide label:

    <label class="hide_dropdown" display='hide'></label>
    

    then everytime you want to hide dropdown, you call:

    $(".hide_dropdown").trigger('click');
    
    0 讨论(0)
  • 2020-12-13 03:52

    The selected answer didn't work for me, but I'm thinking it's because of the newer version of Bootstrap. I ended up writing this:

    $('.btn-navbar').addClass('collapsed');
    $('.nav-collapse').removeClass('in').css('height', '0');
    

    Hopefully that's helpful to someone else in the future.

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

    After click:

    // Hide mobile menu
    $('.in,.open').removeClass('in open');
    // Hide dropdown
    $('.dropdown-menu').css('display','none');
    setTimeout(function(){
        $('.dropdown-menu').css('display','');
    },100);
    
    0 讨论(0)
  • 2020-12-13 03:55
    $('.open').removeClass('open');
    

    Bootstrap 4 (October 2018):

    $('.show').removeClass('show');
    
    0 讨论(0)
提交回复
热议问题