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');}
}
);
});
By default, accordion items expand or collapse by clicking the accordion item header or clicking expand/collapse icon in accordion header. You can also expand or collapse the accordion items through external button click.
Basic collapsible To create a collapsible block of content, create a container and add the data-role="collapsible" attribute. Directly inside this container, add any header (H1-H6) or legend element.
By default, there is no option to close the accordion on click but there is a solution. Add the code to Theme options General options Custom CSS/JS Custom JS field. Note, in case you have links inside the accordion they will not be clickable, they will close the accordion.
jQuery - Widget accordion Accordion is same like as Tabs,When user click headers to expand content that is broken into logical sections.
This can be resolved much easier.
Simply use the jQuery hide/show command on the accordion element ('.ui-widget-content') you want to expand/collapse.
example:
$(document).ready(function() {
$('.expand').click(function() {
$('.ui-widget-content').show();
});
$('.collapse').click(function() {
$('.ui-widget-content').hide();
});
});
See fiddle: http://jsfiddle.net/ekelly/hG9b5/11/
I would add a class or ID to the expand and collapse links then something like this will work
$(document).ready(function() {
$("#expand").click(function(){
('.answer').slideDown('normal');
});
$("#collapse").click(function(){
('.answer').slideUp('normal');
});
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With