jQuery: How to stop propagation of a bound function not the entire event?

后端 未结 2 1136
清歌不尽
清歌不尽 2021-02-11 05:38

I have a click function bound to many elements. It is possible that sometimes these elements may sit within one another. So, the click event is bound to a child and also bound

2条回答
  •  清酒与你
    2021-02-11 06:15

    try someting like this

    $(mySelector).click(function(evt) {
      if (evt.target == evt.currentTarget) {
          ///run your code.  The if statment will only run this click event on the target element
          ///all other click events will still run.
      }
    });
    

提交回复
热议问题