event.delegateTarget

event.delegateTarget

event.delegateTargetReturns: Element

Description: The element where the currently-called jQuery event handler was attached.

  • version added: 1.7event.delegateTarget

This property is most often useful in delegated events attached by .delegate() or -on(), where the event handler is attached at an ancestor of the element being processed- It can be used, for example, to identify and remove event handlers at the delegation point-

For non-delegated event handlers attached directly to an element, event-delegateTarget will always be equal to event-currentTarget-

Example:

When a button in any box class is clicked, change the box's background color to red.

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

© The jQuery Foundation and other contributors
Licensed under the MIT License.
https://api.jquery.com/event.delegateTarget

在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号

意见反馈
返回顶部