"Full Clickable Panel Heading"
Bootstrap 3.1.0 Snippet by BhaumikPatel

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<link href="//netdna.bootstrapcdn.com/bootstrap/3.1.0/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css">
<script src="//netdna.bootstrapcdn.com/bootstrap/3.1.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">
<div class="row">
<div class="col-md-6">
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">
Panel 1</h3>
<span class="pull-right clickable"><i class="glyphicon glyphicon-minus"></i></span>
</div>
<div class="panel-body">
Panel content</div>
</div>
</div>
<div class="col-md-6">
<div class="panel panel-success">
<div class="panel-heading">
<h3 class="panel-title">
Panel 2</h3>
<span class="pull-right clickable"><i class="glyphicon glyphicon-minus"></i></span>
</div>
<div class="panel-body">
Panel content</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="panel panel-info">
<div class="panel-heading">
<h3 class="panel-title">
Panel 3</h3>
<span class="pull-right clickable"><i class="glyphicon glyphicon-minus"></i></span>
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
.clickable
{
cursor: pointer;
}
.clickable .glyphicon
{
background: rgba(0, 0, 0, 0.15);
display: inline-block;
padding: 6px 12px;
border-radius: 4px
}
.panel-heading span
{
margin-top: -23px;
font-size: 15px;
margin-right: -9px;
}
a.clickable { color: inherit; }
a.clickable:hover { text-decoration:none; }
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
$(document).on('click', '.panel-heading span.clickable', function (e) {
var $this = $(this);
if (!$this.hasClass('panel-collapsed')) {
$this.parents('.panel').find('.panel-body').slideUp();
$this.addClass('panel-collapsed');
$this.find('i').removeClass('glyphicon-minus').addClass('glyphicon-plus');
} else {
$this.parents('.panel').find('.panel-body').slideDown();
$this.removeClass('panel-collapsed');
$this.find('i').removeClass('glyphicon-plus').addClass('glyphicon-minus');
}
});
$(document).on('click', '.panel div.clickable', function (e) {
var $this = $(this);
if (!$this.hasClass('panel-collapsed')) {
$this.parents('.panel').find('.panel-body').slideUp();
$this.addClass('panel-collapsed');
$this.find('i').removeClass('glyphicon-minus').addClass('glyphicon-plus');
} else {
$this.parents('.panel').find('.panel-body').slideDown();
$this.removeClass('panel-collapsed');
$this.find('i').removeClass('glyphicon-plus').addClass('glyphicon-minus');
}
});
$(document).ready(function () {
$('.panel-heading span.clickable').click();
$('.panel div.clickable').click();
});
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Related: See More


Questions / Comments:

Wouldn't it be easier to do this?

.panel-title > a {
width: 100%;
display: block;
}

;)

Emil () - 9 years ago - Reply 0


Woww !! great tips
Thank you

Chanon Saelee () - 8 years ago - Reply 0


What to do if I wanted one of the panels to be slid down (opened) by default?

Jackie Danielson () - 9 years ago - Reply 0


Hi, anyone now how can I had a cookie for toggle a panel open or close when I change page ?

Navalex () - 10 years ago - Reply 0


You would probably use something like https://github.com/carhartl... plugin.

maxsurguy () - 10 years ago - Reply 0


Yes, but I don't now how can I do what i want...

Navalex () - 10 years ago - Reply 0


Great snippet, thanks! I had a few troubles with nested panels and found this worked for me: http://bootsnipp.com/snippe... I actually wanted to add this to your code as a pull request (as implied by the fork option) but a far as I can tell I can't do that... Thanks again for sharing

Lewis () - 10 years ago - Reply 0


Hi Lewis!
I have same problem with nested panels.. how did you do it? The link you gave doesn't even work for 1 panel.. Could you help? :)

Karim Belkhiria () - 8 years ago - Reply 0


Nice one! I was looking for this. Is it possible to use Collapse function instead of SlideUp/Down ?

VentyCZ () - 10 years ago - Reply 0