liveBook · Manning

Event target

As explained in Web Components in Action

event.target is the DOM event property identifying the original element on which an event occurred.

When a click listener runs on a broad container such as document, event.target identifies the original element where the event began. For a button click, it is the button—the first stop before bubbling continues. section 14.3

Separate the three useful views of a propagating event:

  • event.target is the originating element. section 14.3
  • event.currentTarget is the element where the listener was registered, such as document. section 14.3
  • event.composedPath() returns the complete bubbling path, from the clicked element through containing nodes to Window. section 14.3

Inspecting a Web Component click

A document-level click listener can log e.target, e.currentTarget, and e.composedPath() while a custom element supplies a clickable button. The resulting path includes the button, the component, body, html, document, and Window.

How Web Components in Action covers it

How deep it goes
Explains bubbling, listener targets, complete paths, and Shadow DOM paths through concrete Web Component examples.
Examples
Uses a clickable button, a custom element, a document listener, and logged propagation paths.
What it assumes
Assumes familiarity with DOM events and Web Components while distinguishing event origin from listener location.
What you can do after
Diagnose event origins and propagation by logging target, currentTarget, and composedPath().
How it connects
Connects event.target with event bubbling, event.currentTarget, composedPath(), Web Components, Shadow DOM, and CustomEvent.

Also explained in

Compare how 3 books explain event target →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Web Components in Action. The section links point to the parts of the book it draws on.