I'm using Bootstrap to make collapsible nested divs/buttons. I want to collapse all siblings of a div when it is expanded and to collapse all children of a div when it is collapsed (so that the expanded divs are from only one path from one of the root divs to an inner div).
I choose to do it with jQuery and not using Bootstrap's Accordion - just buttons with associated divs.
So I tried to select all divs that could expand and use the show.bs.collapse event, so that I would know which div was expanded.
$(function () {
$(".collapse").on('show.bs.collapse', function () {
console.log ($(this).context.id);
})
});
If my tree is like so:
1 - expanded
2 - expanded
- 3 - collapsed
4 - collapsed
5 - collapsed
6 - collapsed
and I expand 3, I don't get:
3
but:
3
2
1
Why is show.bs.collapse applied to divs 1 and 2?
Try using
shown.bs.collapse
instead. http://www.tutorialspoint.com/bootstrap/bootstrap_collapse_plugin.htmsection
The following table lists a few events that can be used with the collapse functionality.
Try