Latest web development tutorials

jQuery event.delegateTarget property

jQuery Event Methods jQuery Event Methods

Examples

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

$("div").on("click","button",function(event){
    $(event.delegateTarget).css("background-color", "pink");
});

try it"

Definition and Usage

event.delegateTarget property returns jQuery event handler is currently called the added element.

This attribute made on () method to add event delegates are very useful when the event handler is the ancestor element is processed to add.

Tip: If the event is bound directly to the elements and no commission occurs, event.delegateTarget equivalent event.currentTarget (see example below).


grammar

event.delegateTarget

参数 描述
event 必需。 event 参数来自事件绑定函数。


Examples

More examples

and with different delegateTarget commissioned between currentTarget
DelegateTarget different presentation and occurs when a delegate currentTarget between.

For direct binding events, delegateTarget and currentTarget are equal
Demo for direct binding events, delegateTarget and currentTarget are equal.


jQuery Event Methods jQuery Event Methods