Reputation: 2794
I have multiples accordions in the same page. Some of them inside another accordion.
When one panel is clicked, I need to close all open panels. This is simple:
$('.panel-group').on('show.bs.collapse', function (event) {
$('.collapse.in').collapse('hide');
});
But I need to check if the panel is not parent of the clicked panel. How can I do this?
An example of my issue: http://codepen.io/anon/pen/RRkBJw?editors=1010
Upvotes: 0
Views: 1308
Reputation: 2794
Found a solution:
$('.panel-group').on('show.bs.collapse', function (event) {
var parent = $(event.target).parents('.collapse.in');
$('.collapse.in').not(parent).collapse('hide');
});
Upvotes: 1
Reputation: 5550
I had a similar problem with nested accordions. The following answer might help. See this answer/question.
Upvotes: 1