I grabbed a great collapsible accordion code from a site (inspirationalpixels). It's working great except the problem is whenever I click on the word "WEIRD PART", the panel opens again which it shouldn't be. When I click the word "Chapter 1", accordion works okay. There is a span class enclosed on the word maybe that's it? You'll see what I mean here
HTML Code:
<h2><a class="bb-sc-title" href="#chapter01">Chapter 1 <span>WEIRD PART</span></a> </h2>
<div id="chapter01" class="bb-story-content">
<p>Mauris interdum fringilla augue vitae tincidunt. Curabitur vitae tortor id eros euismod ultrices. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Praesent nulla mi, rutrum ut feugiat at, vestibulum ut neque? Cras tincidunt enim vel aliquet facilisis. Duis congue ullamcorper vehicula. Proin nunc lacus, semper sit amet elit sit amet, aliquet pulvinar erat. Nunc pretium quis sapien eu rhoncus. Suspendisse ornare gravida mi, et placerat tellus tempor vitae.</p>
</div><!--end .accordion-section-content-->
</div><!--/bb-sc-chapter01-->
<div class="bb-sc-chapter02">
<h2><a class="bb-sc-title" href="#chapter02">Chapter 2 <span>WEIRD PART</span></a></h2>
<div id="chapter02" class="bb-story-content">
<p>Mauris interdum fringilla augue vitae tincidunt. Curabitur vitae tortor id eros euismod ultrices. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Praesent nulla mi, rutrum ut feugiat at, vestibulum ut neque? Cras tincidunt enim vel aliquet facilisis. Duis congue ullamcorper vehicula. Proin nunc lacus, semper sit amet elit sit amet, aliquet pulvinar erat. Nunc pretium quis sapien eu rhoncus. Suspendisse ornare gravida mi, et placerat tellus tempor vitae.</p>
</div><!--end .accordion-section-content-->
</div><!--/bb-sc-chapter02-->
<div class="bb-sc-chapter03">
<h2><a class="bb-sc-title" href="#chapter03">Chapter 3 <span>WEIRD PART</span></a></h2>
<div id="chapter03" class="bb-story-content">
<p>Mauris interdum fringilla augue vitae tincidunt. Curabitur vitae tortor id eros euismod ultrices. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Praesent nulla mi, rutrum ut feugiat at, vestibulum ut neque? Cras tincidunt enim vel aliquet facilisis. Duis congue ullamcorper vehicula. Proin nunc lacus, semper sit amet elit sit amet, aliquet pulvinar erat. Nunc pretium quis sapien eu rhoncus. Suspendisse ornare gravida mi, et placerat tellus tempor vitae.</p>
</div><!--end .accordion-section-content-->
<hr>
</div><!--/bb-sc-chapter03-->
</div><!--/bb-story-chapters-->
JS Code:
jQuery(document).ready(function() {
function close_accordion_section() {
jQuery('.bb-story-chapters .bb-sc-title').removeClass('active');
jQuery('.bb-story-chapters .bb-story-content').slideUp(300).removeClass('open');
}
jQuery('.bb-sc-title').click(function(e) {
// Grab current anchor value
var currentAttrValue = jQuery(this).attr('href');
if(jQuery(e.target).is('.active')) {
close_accordion_section();
}else {
close_accordion_section();
// Add active class to section title
jQuery(this).addClass('active');
// Open up the hidden content panel
jQuery('.bb-story-chapters ' + currentAttrValue).slideDown(300).addClass('open');
}
e.preventDefault();
});
});