Bootstrap Tutorial - Toggle All Collapse








The following code shows how to toggle All Collapse.

Example

<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'
  src='http://code.jquery.com/jquery-1.10.1.js'></script>
<link rel="stylesheet" type="text/css"
  href="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">
<script type='text/javascript'
  src="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
<script type='text/javascript'>
$(window).load(function(){<!--from   w  w  w  .  j  a  va 2s.  c o  m-->
    $('#accordion .panel-default').on('click', function () {
        $('#accordion .panel-collapse').collapse('toggle');
    });
});
</script>
</head>
<body style='margin:30px'>
  <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>
    <!-- Second Panel -->
    <div class="panel panel-default">
      <div class="panel-heading">
        <h4 class="panel-title" data-toggle="collapse"
          data-target="#collapseTwo">Collapsible Group Item #2</h4>
      </div>
      <div id="collapseTwo" class="panel-collapse collapse">
        <div class="panel-body">Anim pariatur cliche reprehenderit,
          enim eiusmod high life accusamus terry richardson ad squid.</div>
      </div>
    </div>
    <!-- Third Panel -->
    <div class="panel panel-default">
      <div class="panel-heading">
        <h4 class="panel-title" data-toggle="collapse"
          data-target="#collapseThree">Collapsible Group Item #3</h4>
      </div>
      <div id="collapseThree" class="panel-collapse collapse">
        <div class="panel-body">Anim pariatur cliche reprehenderit,
          enim eiusmod high life accusamus terry richardson ad squid.</div>
      </div>
    </div>
  </div>
</body>
</html>

Click to view the demo