When using jQuery’s Accordion (in a nested fashion), I want to ensure that when a parent element is clicked/opened, any open children are closed/rolled up. I’m not sure what selector(s) I should use when attempting to do this. So far I’ve tried rigging a change event with “activate” set to false, but that simply makes any element that is opened automatically close.
Assuming I only have 1 nested accordion, my jquery initialization looks like:
$(".accordion").accordion({
active: false, collapsible: true, autoHeight: false, animated: 'swing'
});
$(".child-accordion").accordion({
active: false, collapsible: true, autoHeight: false, animated: 'swing',
change: function(event, ui) { $(".child-accordion").accordion("activate", false); }
});
where .child-accordion is the nested instance. I need anything under the .child-accordion to be closed when a member of the .accordion is opened.
The reason your version wasn’t working is two-fold
Your change event needs to be on the parent, because that’s when you want the children to roll up
You need to make the event
changestartbecause when you setactivateto false, the main thing it does istogglethe currently “visible” section in the child, but when thechangeevent triggers on the parent, the child is already hidden, so it doesn’t do anything.EDIT: here’s a working version of this http://jsfiddle.net/ryleyb/YPpEn/