Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Twitter-bootstrap collapse plugin - how to enable multiple "groups" to be opened?

I'm working with the collapse plugin and I'm wondering how I can enable multiple groups to be open at the same time. In their demo page:

http://twitter.github.com/bootstrap/javascript.html#collapse

Only one is allowed to be open at a given time. I suppose this is the expected behavior of accordions, but how can I change it so that opening one group does not collapse the others?

like image 765
RobVious Avatar asked Mar 29 '13 02:03

RobVious


People also ask

How do you keep multiple collapses open in bootstrap 4?

Assuming that you're using Bootstrap 4, you can simply remove the data-parent attribute from the element with the collapse class. This subscribes the collapse to events on #accordionExample , which is the main accordion element, via the data-parent attribute.

How do I collapse a bootstrap plugin?

Just add data-toggle="collapse" and a data-target to element to automatically assign control of a collapsible element. The data-target attribute accepts a CSS selector to apply the collapse to. Be sure to add the class collapse to the collapsible element. If you'd like it to default open, add the additional class in.

What is Bootstrap collapse?

The collapse JavaScript plugin is used to show and hide content. Buttons or anchors are used as triggers that are mapped to specific elements you toggle. Collapsing an element will animate the height from its current value to 0 .


2 Answers

Just don't use data-parent attributes:

<div class="accordion" id="accordion2">   <div class="accordion-group">     <div class="accordion-heading">       <a class="accordion-toggle" data-toggle="collapse" href="#collapseOne">         Collapsible Group Item #1       </a>      </div>     <div id="collapseOne" class="accordion-body collapse in">       <div class="accordion-inner">Item 1 Body</div>     </div>   </div>   <div class="accordion-group">     <div class="accordion-heading">        <a class="accordion-toggle" data-toggle="collapse" href="#collapseTwo">         Collapsible Group Item #2       </a>     </div>     <div id="collapseTwo" class="accordion-body collapse">       <div class="accordion-inner">Item 2 Body</div>     </div>   </div> </div> 

http://jsfiddle.net/HJf6j/2/

like image 150
sody Avatar answered Oct 17 '22 23:10

sody


For a solution that expands/collapses each panel dependently and allows multiple accordions on each page.

If all your accordions and groups have unique ids then you can have as many accordions on the page as you want

Each accordion needs a unique id:

<div class="panel-group" id="accordion1" role="tablist" aria-multiselectable="true"> 

Each heading needs a unique id

<div class="panel-heading" role="tab" id="headingOne">   

Each body needs a unique id, and if applicable a reference the the heading to be used

<div id="collapseOne" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingOne"> 

Example on JSFiddle: http://jsfiddle.net/qnhd7Lu3/3/

like image 43
dinamite Avatar answered Oct 18 '22 00:10

dinamite