jQuery: clicking nested elements

前端 未结 5 1797
粉色の甜心
粉色の甜心 2021-01-04 10:13

I have the following markup

  1. @qItem.CategoryText
5条回答
  •  鱼传尺愫
    2021-01-04 10:56

    You need to use event.stopPropagation() to prevents the event from bubbling up the DOM tree.

    $(".deleteIcon").click(function(event){
        event.stopPropagation()
        doActionA();    
    });
    

    The event you binded with delete icon is firing the parent event binding with ListItem, so you need to stop propagation for parent event when child is source of event.

提交回复
热议问题