"Spoiler - Collapsable panel"
Bootstrap 3.2.0 Snippet by VentyCZ

<link href="//netdna.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css"> <script src="//netdna.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script> <script src="//code.jquery.com/jquery-1.11.1.min.js"></script> <!------ Include the above in your HEAD tag ----------> <div class="container"> <h2>Spoiler - using panel</h2> <h4>Use</h4> <p>Use <code>autocollapse</code> class on main <code>panel</code> element to auto-close spoiler on page-load.</p> <p>Use <code>clickable</code> class on <code>panel-heading</code> element to be able to collapse the panel.</p> <h4>Examles</h4> <div class="panel panel-primary"> <div class="panel-heading clickable"> <h3 class="panel-title">Primary Title</h3> </div> <div class="panel-body"> <div class="row"> <div class="col-md-6"> <div class="panel panel-success autocollapse"> <div class="panel-heading clickable"> <h3 class="panel-title"> Success Title </h3> </div> <div class="panel-body"> <div class="alert alert-danger" role="alert">SPOILER ALERT!</div> </div> </div> <div class="panel panel-warning autocollapse"> <div class="panel-heading clickable"> <h3 class="panel-title"> Warning Title </h3> </div> <div class="panel-body"> <div class="alert alert-danger" role="alert">SPOILER ALERT!</div> </div> </div> </div> <div class="col-md-6"> <div class="panel panel-info autocollapse"> <div class="panel-heading clickable"> <h3 class="panel-title"> Information Title </h3> </div> <div class="panel-body"> <div class="alert alert-danger" role="alert">SPOILER ALERT!</div> </div> </div> <div class="panel panel-danger autocollapse"> <div class="panel-heading clickable"> <h3 class="panel-title"> Danger Title </h3> </div> <div class="panel-body"> <div class="alert alert-danger" role="alert">SPOILER ALERT!</div> </div> </div> </div> </div> </div> </div> </div>
.clickable { cursor: pointer; }
$(document).on('click', '.panel div.clickable', function (e) { var $this = $(this); //Heading var $panel = $this.parent('.panel'); var $panel_body = $panel.children('.panel-body'); var $display = $panel_body.css('display'); if ($display == 'block') { $panel_body.slideUp(); } else if($display == 'none') { $panel_body.slideDown(); } }); $(document).ready(function(e){ var $classy = '.panel.autocollapse'; var $found = $($classy); $found.find('.panel-body').hide(); $found.removeClass($classy); });

Related: See More


Questions / Comments: