最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Bootstrap Nested Collapse With Events Only On Parent Collapse - Stack Overflow

programmeradmin2浏览0评论

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: /

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/

Share Improve this question asked Jan 14, 2013 at 20:17 MichaelMichael 1,8667 gold badges22 silver badges35 bronze badges 1
  • 2 I have a similar issue. I have nested collapse elements, and when I collapse the child, the .show() event triggers on the parent as well. I tried stopPropogation() with no luck. Any ideas? – Jo Sprague Commented Jun 28, 2013 at 14:01
Add a comment  | 

1 Answer 1

Reset to default 26

You can use stopPropagation method of the event object.

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

http://jsfiddle.net/SPZZv/

发布评论

评论列表(0)

  1. 暂无评论