I am using Twitter Bootstrap to create collapsible sections of text. The sections are expanded when a + button is pressed. My html code as follows:
<div class="panel-group" id="accordion">
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
<button type="button" class="btn btn-primary" data-toggle="collapse" data-target="#demo">
<span class="glyphicon glyphicon-chevron-down"></span> Open
</button>
</h4>
</div>
<div id="demo" class="panel-collapse collapse in">
<div class="panel-body">
Contents:Thank you to help me solve the problem, you're a great guy!
</div>
</div>
</div>
</div>
Later, i need to change text, button icons and expand.
Is Open:
<button type="button" class="btn btn-primary" data-toggle="collapse" data-target="#demo">
<span class="glyphicon glyphicon-chevron-up"></span> Close
</button>
Is Close:
<button type="button" class="btn btn-primary" data-toggle="collapse" data-target="#demo">
<span class="glyphicon glyphicon-chevron-down"></span> Open
</button>
It is also possible to do by css styles.
in css add style:
and use in html:
Please remember to add attribute
and class
to link / button.
I found this question and answer helpful. I removed the parent() method and added an id to my + button to avoid changing other buttons when toggling +.
http://jsfiddle.net/maybolles/opbyvbv4/2/
If you're using jQuery then make use of
toggleClass
Working JSFiddle here
based on: https://stackoverflow.com/a/16870379/1596547
use this javascript for changing icon