Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save omurphy27/169ddbb939a03e2977a7 to your computer and use it in GitHub Desktop.
Save omurphy27/169ddbb939a03e2977a7 to your computer and use it in GitHub Desktop.
jQuery - add active class to bootstrap accordion panel heading.js
// jQuery - add active class to Bootstrap Accordion Heading
if ($('#accordion').length) {
var $panels = $('.panel');
// add active class to first open panel
// only necessary if this panel is open by default on your accordion
$panels.first().addClass('active');
$('.panel-heading').on('click', function (e) {
$this = $(this);
$panel = $this.parents('.panel');
$panels.not( $panel ).removeClass('active');
$panel.toggleClass('active');
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment