JQuery stopPropagation on .live() when handlers already exist and are bound

后端 未结 3 1325
情深已故
情深已故 2021-01-27 07:21

I\'m aware that live calls bubble up through the doccument and that is why I\'m having issues.

Unfortunately I\'m using third party libraries that bind elements and wou

3条回答
  •  自闭症患者
    2021-01-27 08:01

    use on delegate bound to outer and call e.stopPropagation() in inner click handler..this should dothe trick.

    try this updated

    $("#outer").bind('click',function(e){
      alert("outer clicked"); 
    });
    
    $('#outer').on('click',"#inner",function(e){
      e.stopPropagation();
      alert("inner clicked"); 
    
    });
    

    updated fiddle here

提交回复
热议问题