Bootstrap Tutorial - Keep Accordions Open








The following code shows how to keep Accordions Open.

Example

<!--from   ww  w.  j a  v  a2 s. com-->
<!--
Code revised from 
http://fiddle.jshell.net/f8ypa/10/
-->

<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'
  src='http://code.jquery.com/jquery-2.0.2.js'></script>
<link rel="stylesheet" type="text/css"
  href="http://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css">
<script type='text/javascript'
  src="http://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
<link rel="stylesheet" type="text/css"
  href="http://netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.min.css">
<style type='text/css'>
.panel-title:hover {
  cursor: pointer;
}
</style>
<script type='text/javascript'>//<![CDATA[ 
$(window).load(function(){
$(function () {
    var active = true;
    $('#collapse-init').click(function () {
        if (active) {
            active = false;
            $('.panel-collapse').collapse('show');
            $('.panel-title').attr('data-toggle', '');
            $(this).text('Enable accordion behavior');
        } else {
            active = true;
            $('.panel-collapse').collapse('hide');
            $('.panel-title').attr('data-toggle', 'collapse');
            $(this).text('Disable accordion behavior');
        }
    });
    $('#accordion').on('show.bs.collapse', function () {
        if (active) $('#accordion .in').collapse('hide');
    });
});
});
</script>
</head>
<body>
  <button id="collapse-init" class="btn btn-primary">Disable
    accordion behavior</button>
  <br />
  <br />
  <div class="panel-group" id="accordion">
    <!-- First Panel -->
    <div class="panel panel-default">
      <div class="panel-heading">
        <h4 class="panel-title" data-toggle="collapse"
          data-target="#collapseOne">Collapsible Group Item #1</h4>
      </div>
      <div id="collapseOne" class="panel-collapse collapse">
        <div class="panel-body">Anim pariatur cliche reprehenderit,
          enim eiusmod high life accusamus terry richardson ad squid.</div>
      </div>
    </div>
</body>
</html>

Click to view the demo