Stop propagation on live elements

后端 未结 2 1649
死守一世寂寞
死守一世寂寞 2020-12-22 12:01

I\'m having an issue with stopping event propagation. Imagine this scenario:



        
      
      
      
2条回答
  •  暖寄归人
    2020-12-22 12:56

    Maybe I'm wrong, but can't you use event delegation here?

    (function(){
        $('#test').on('click', function(e){
            if ( !/img$/i.test((e.target || e.eventSrc).nodeName)){
              alert('row clicked');
            } else {
              alert('image clicked');
            }           
    
        });
        $('td.row').html('');
    })();​
    

    It saves you the hassle with propagation. Here's a jsfiddle

提交回复
热议问题