English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The event.target attribute returns which DOM element triggered the event.
The target attribute can be the element on which the event is registered or its descendants.
Comparing event.target is often very useful, this to determine whether the event is being processed due to event bubbling.
event.target
Show which DOM element triggered the event:
$("*").click(function(event){ $("#output").text("Triggered by " + event.target.tagName + " element."); });Test and see‹/›
This property is very useful in event delegation when the event bubbles up:
$("ul li").click(function(){ $("#output").text("List item " + event.target.id.replace("post"-", "") + " was clicked!"); });Test and see‹/›
Parameter | Description |
---|---|
event | TheEventParameters come from the event binding feature |