Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Accordion that opens first heading when any is closed Re: Accordion that opens first heading when any is closed

#81992

I haven’t tested this with the extra part your looking to add, but it should at least be in the general area of the solution.


// Accordion effect
$('#some-id a').click(function(){

// Show next element if hidden
if ($(this).next().is(':hidden')) {
// Hide all other elements
$('#some-id a')
.next()
.slideUp();
$(this).next()
.slideDown();
}
// Element already shown - slide up element, show first
else
{
$(this)
.next()
.slideUp();
$('#some-id a')
.first()
.next()
.slideUp();
}
return false;

});