Bootstrap Collapse doesn't toggle after you show, hide or toggle from code

后端 未结 3 758
清歌不尽
清歌不尽 2021-02-05 07:20

My HTML is:

相关标签:
3条回答
  • 2021-02-05 07:43

    Try activating your content as a collapsible element first. I skimmed over this part when reading the documentation and it really stumped me.

    $('#myCollapsible').collapse({
        toggle: false
    })
    

    After you activate it you can hide and show it as usual.

    $('#myCollapsible').collapse('hide');
    $('#myCollapsible').collapse('show');
    

    http://getbootstrap.com/javascript/#collapse-methods

    0 讨论(0)
  • 2021-02-05 07:44

    1.Try to use collapse() with options, the 'parent' is important

    $("#collapseMenu").collapse({"toggle": true, 'parent': '#navaccordion'});
    $("#collapseQuickLinks").collapse({"toggle": true, 'parent': '#navaccordion' });
    

    Fiddle: http://jsfiddle.net/hieuh25/Xut4C/6/

    2.Basically you have 2 ways:

    • Add class in to that div, e.g: <div id="collapseMenu" class="accordion-body collapse in"> cause that div to open.

    • Use collapse() with option 'toggle': true as above, when the div is closed.

    Hope it helps.

    0 讨论(0)
  • 2021-02-05 07:52

    You also can add data-parent="#navaccordion" to <div id="collapseMenu" class="accordion-body collapse" data-parent="#navaccordion"> and call without addional key 'parent' like .collapse({"toggle": true});

    0 讨论(0)
提交回复
热议问题