Reputation: 269
Is there a way to make the jQuery accordion collapse when you click off of it? For example if you have one of the accordions open, if you click anywhere that isn't the accordion, then it closes.
jQuery
$(document).ready(function() {
$( "#accordion" ).accordion({
header: "h3",
collapsible: true,
active: false,
heightStyle: "content",
animate: {
easing: "swing",
duration: 300
}
});
});
Upvotes: 2
Views: 966
Reputation: 8311
How about this:
$(document).click(function (event) {
if(!$(event.target).closest('#accordion').length) {//if you clicked outside of the accordion
$("#accordion").accordion({active: false});//collapse all the panels
}
});
Upvotes: 3