Prevent nested elements from triggering an event for parent element

后端 未结 2 1652
时光取名叫无心
时光取名叫无心 2020-12-09 05:14

Structure:

.parent (has if/else to toggle on click) -> .child (has nothing)

Parent
2条回答
  •  佛祖请我去吃肉
    2020-12-09 05:47

    Use event.stopPropagation();:

    $('#a').add('#b').click(fun1);
    
    function handler(event) {
        event.stopPropagation();
        // now do your stuff        
    }
    

提交回复
热议问题