I've set up this simple version of the Bootstrap accordion:
Simple accordion: http://jsfiddle.net/darrenc/cngPS/
Currently the icon only points down, but does anyone know what JS would be needed to be implemented so as to change the class of the icon to:
<i class="icon-chevron-up"></i>
...so that it points up when expanded and toggles back to down again when collapsed, and so fourth?
You can add the icon custom css class to the Accordion header using 'iconCss' property and also add css styles to the defined class. The accordion icon element is rendered before the header text in the DOM element.
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.
Here it's the answer for those who are looking for a solution in Bootstrap 3(like myself).
<div class="btn-group"> <button type="button" class="btn btn-danger">Action</button> <button type="button" class="btn btn-danger" data-toggle="collapse" data-target="#demo"> <span class="glyphicon glyphicon-minus"></span> </button> </div> <div id="demo" class="collapse in">Some dummy text in here.</div>
$('.collapse').on('shown.bs.collapse', function(){ $(this).parent().find(".glyphicon-plus").removeClass("glyphicon-plus").addClass("glyphicon-minus"); }).on('hidden.bs.collapse', function(){ $(this).parent().find(".glyphicon-minus").removeClass("glyphicon-minus").addClass("glyphicon-plus"); });
Bootply accordion example
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With