Thursday, January 12, 2012

Custom Accordion


I have the accordion below which works but when an item is open if you click it again it re opens instead of closing.



I'm not sure of the best way to adapt the code below to achieve this?



Any help or advice would be great?



Thanks




$('.acc h2').click(function() {
$('.acc h2.open').nextUntil('h2').stop(true, true).slideToggle();
$('.acc h2.open').removeClass('open');
$(this).nextUntil('h2').stop(true, true).slideToggle(900);
$(this).toggleClass('open');
});

<div class="acc">

<h2>1. Title 1</h2>
<div><p>text 1</p></div>

<h2>2. Title 2</h2>
<div><p>text 2</p></div>

<h2>3. Title 3</h2>
<div><p>text 3</p></div>

</div><!--END acc-->

No comments:

Post a Comment