Skip to content
Tutorials Center
My learning

Topics

JavaScript Reference ยท DOM: Events

Event.target and Event.currentTarget

Reference for event.target, currentTarget, relatedTarget and composedPath(): find the element that triggered an event and the one whose listener is running.

Every event object tells you two different things about where it is. event.target is the element where the event originated, for example the exact button, icon or text container the user clicked. event.currentTarget is the element whose listener is running right now, which is the object you called addEventListener() on.

They are the same when you listen directly on the element that was clicked. They differ as soon as an event bubbles up from a descendant to a listener on an ancestor.

JavaScript
list.addEventListener("click", (event) => {
  console.log(event.target);        // the element that was clicked
  console.log(event.currentTarget); // always `list`
});

Try it

target is the clicked element, currentTarget is the listener's element
relatedTarget and composedPath()

Syntax

JavaScript
event.target
event.currentTarget
event.relatedTarget   // mouse, focus and pointer events only
event.composedPath()

Properties and methods

Name Description
target The object the event was dispatched to: the innermost element for a user action. Read-only.
currentTarget The object whose listener is currently being called. It is null once the dispatch has finished.
relatedTarget On mouseover/mouseout/mouseenter/mouseleave and focusin/focusout/focus/blur, the other element involved in the change, or null.
composedPath() Returns an array of the objects the event will pass or has passed, from the target up to window.

Usage notes

  • target may be a child you did not expect. Clicking an icon inside a button gives you the icon, not the button. Use event.target.closest("button") to climb to the element you care about.
  • Arrow functions and this. In an arrow function there is no this bound to the element, so use event.currentTarget. In a regular function this === event.currentTarget.
  • currentTarget is reset. Reading it asynchronously, after an await or inside setTimeout(), gives null. Save it in a variable first.
  • Shadow DOM retargeting. When an event crosses a shadow boundary, target is retargeted to the shadow host for listeners outside. composedPath() shows the real path only for open shadow roots.
  • this vs delegation. In delegated listeners, currentTarget is the container and target identifies the child. See event delegation.
  • event.srcElement. A legacy alias of target. Do not use it.

Browser support

target, currentTarget and relatedTarget work in every browser. composedPath() is supported in all current browsers.