event.delegateTarget

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

.event.delegateTarget()🡢 Element

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.

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

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

Looking for a Web Developer?

👋

Hi! I'm Basti, author of this site. If you are looking for a web developer with 15+ years of experience, holla at me!

Be it the good 'ol jQuery, vanilla JS or modern frameworks like Vue and Svelte, front- or backend, I can help you.

Just write me at jobs@jqapi.com :)