jQuery click event on parent, but finding the child (clicked) element

Mahdi提出了一个问题:jQuery click event on parent, but finding the child (clicked) element,或许与您遇到的问题类似。

回答者Adil给出了该问题的处理方式:

You need to pass event object to function to get the item that triggered the event, event.target will give you the source element.

Live Demo

 --------------------- --------------- -
    -----------------------
 ---

or

Live Demo

--------------------- --------------- -
    ----------------------------------
---

Edit

The first method event.target.id is preferred over second $(event.target).attr('id') for performance, simplicity and readability.

希望本文对你有帮助,欢迎支持JavaScript中文网

来源:JavaScript中文网 ,转载请注明来源 本文地址:https://www.javascriptcn.com/post/25970