jQuery event.delegateTargetProperty
Example
Change the background color of the <div> element (the ancestor of the <button> element):
$(event.delegateTarget).css("background-color", "pink");
});
Try it yourself »
Definition and Usage
The event.delegateTarget property returns the element to which the currently called jQuery event handler was attached.
This property is very useful for delegated events added by theon()method. The event handler is attached when the ancestor of the element is processed.
Tip:If the event is directly bound to the element and no delegation occurs, then event.delegateTarget is equivalent toevent.currentTarget(see the example below).
Syntax
| Parameter | Description |
|---|---|
| event | Required.eventThe parameter comes from the event binding function. |
More Examples
The difference between delegateTarget and currentTarget with delegation
Demonstrates the difference between delegateTarget and currentTarget when delegation occurs.
For directly bound events, delegateTarget and currentTarget are equal
Demonstrates that delegateTarget and currentTarget are equal for directly bound events.
Other extensions
jQuery Event Methods