Call of bootstrap collapse('show') hide element only the first time

Getz picture Getz · Feb 27, 2014 · Viewed 7.2k times · Source

I'm using Bootstrap v2.3.2 with a collapse element.

My accordion looks like this:

<div class="accordion" id="accordion">
        <div class="accordion-heading">
             <a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion" href="#collapseOne">
               <strong><i class="icon-chevron-down"></i>Search options</strong>
             </a>
        </div>
        <div id="collapseOne" class="accordion-body collapse in">
            <div class="accordion-inner">
                Hello
            </div>
        </div>
    </div>
</div>

If i collapse the element #collapseOne by clicking on it, no problem.

But if i call the function$("#collapseOne").collapse('show'); , the element will hide except of showing, but only on first call and only if i don't collapse the element clicking on it before that. I think i forgot a HTML element, but i can't see any difference into DOM...

Fiddle : click on the 'click me' button without clicking on collapsible element before.


Already try: add $accordion.collapse({toggle:true}) (https://github.com/twbs/bootstrap/issues/5859) but it didn't worked...

Answer

alpakyol picture alpakyol · Feb 27, 2014

$accordion.collapse({toggle:false}) fixes toggle issue, but on wrong element.

You need to fix on #collapseOne

$("#collapseOne").collapse({toggle:false});

FIDDLE