首頁  >  事件對像  > eve.delegateTarget

返回值: Element event.delegateTarget

V1.7 概述

當currently-called的jQuery事件處理程式附加元素。

此屬性是最經常有用是通過過 .delegate()  或 .on() 附加委派的事件,事件處理程式附加在正在處理的元素的祖先上。它可用於,例如,指明委派識別和刪除事件處理程式。 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.

對於非授權的事件處理程式,直接連線到一個元素,event.delegateTarget 總是等價于event.currentTarget.

示例

描述:

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

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