Michael
Michael

Reputation: 1886

Bootstrap Nested Collapse With Events Only On Parent Collapse

I have a nested Bootstrap Collapse with a shown event firing on both the parent and the child Collapse. I need it to only fire on the parent Collapse and not on the child.

$(document).ready(function() {
  $("#accordion2").on("shown",function() {
    alert("shown!");  
  });
});

Here's an example: http://jsfiddle.net/xb9K6/

Upvotes: 9

Views: 4466

Answers (1)

Ram
Ram

Reputation: 144739

You can use stopPropagation method of the event object.

$(".accordion").on("shown",function(event) {
    event.stopPropagation();
});

http://jsfiddle.net/SPZZv/

Upvotes: 26

Related Questions