Is there any way to check if bubble triggered the click?

后端 未结 5 1488
谎友^
谎友^ 2020-12-24 06:07

Clicking on elements in jQuery causes bubble up to body. If we have a click handler binded to body that shows an alert, then clicking on any element will bubble up to body a

5条回答
  •  生来不讨喜
    2020-12-24 06:11

    The "event" parameter passed to the handler has a "target" property, which refers to the element that was the direct target of the event. You can check that property to see if it's the element.

    Note that the jQuery ".delegate()" facility can be used to do that checking for you.

提交回复
热议问题