Jquery click event propagation

前端 未结 2 1545
無奈伤痛
無奈伤痛 2020-12-10 02:57

I have a table with click events bound to its rows (). There are elements inside those rows with their own click events assigne

相关标签:
2条回答
  • 2020-12-10 03:47

    You have to stop event bubbling. In jQuery you can do this by

    e.stopPropagation();
    

    in the onclick event of the anchor tag.

    $("a").live("click",function(e){alert("clicked!");e.stopPropagation();});
    

    Edit

    See this post

    jquery Event.stopPropagation() seems not to work

    0 讨论(0)
  • 2020-12-10 03:53

    I would use bind instead of live for both <tr> and <a> and the following code

    $("a").bind("click", function(e){ alert("clicked!"); e.stopPropagation() });

    for <a>.

    All <a href>'s will work as expected and <tr> event handler code won't execute after clicking <a>.

    Works in all modern browsers.

    0 讨论(0)
提交回复
热议问题