I was looking for a way to include an “expand all” and “collapse all”. I’ve updated the demo with the new code using a simple jquery accordion.
The original code should be credited to Ryan Stemkoski at http://www.stemkoski.com/stupid-simple-jquery-accordion-menu/
Demo: http://jsbin.com/ucalu3/5/
$(document).ready(function() {
$('.question').click(function() {
if($(this).next().is(':hidden') != true) {
$(this).removeClass('active');
$(this).next().slideUp("normal");
} else {
$('.question').removeClass('active');
$('.answer').slideUp('normal');
if($(this).next().is(':hidden') == true) {
$(this).addClass('active');
$(this).next().slideDown('normal');
}
}
});
$('.answer').hide();
$('.expand').click(function(event)
{$('.question').next().slideDown('normal');
{$('.question').addClass('active');}
}
);
$('.collapse').click(function(event)
{$('.question').next().slideUp('normal');
{$('.question').removeClass('active');}
}
);
});
I would add a class or ID to the expand and collapse links then something like this will work