jQuery event.delegateTargetProperty

jQuery 事件方法jQuery Event Methods

Example

Change the background color of the <div> element (the ancestor of the <button> element):

$("div").on("click","button",function(event){
    $(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

event.delegateTarget

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.


jQuery 事件方法jQuery Event Methods

Other extensions