addEventListener
addEventListener is a method that registers a callback to be invoked when a specified event is dispatched to an event target.
Vanilla Web
addEventListener is a DOM API method that registers a callback for events of a specified type on an event target.
- How it is used
- Registers composable handlers for DOM events and lets custom-element consumers receive events through the same API.
- How deep it goes
- Explains registration, capture and bubble phases, listener options, and removal through small implementations.
- Examples
- Uses a passive scroll handler, capture and bubble listeners, and a custom rating element’s change event.
- What you can do after
- Operate/configure it on DOM targets to add, tune, and remove listeners for native and custom events.
React Quickly, Second Edition
addEventListener is a browser API method that registers a function to be invoked for a specified event on an event target.
- How it is used
- Registers browser-level handlers for window, document, and referenced DOM nodes outside React’s event properties.
- How deep it goes
- Explains registration, capture options, propagation phases, React effects, state updates, and unmount cleanup.
- Examples
- Demonstrates click listeners, capture listeners, referenced DOM nodes, and a React window-resize display.
- What you can do after
- Operate/configure direct browser listeners, select capture behavior, update React state, and remove handlers during unmount.
Read how React Quickly, Second Edition explains addEventListener →
Secrets of the JavaScript Ninja, Second Edition
A DOM method for registering an event listener on an event target without replacing existing listeners for the same event type.
- How it is used
- Registers browser event handlers so client-side applications can respond to user actions.
- How deep it goes
- Defines registration, contrasts property assignment, and demonstrates multiple event types; leaves event-processing flow for later.
- Examples
- Demonstrates body mousemove and click handlers that append labeled messages to a list.
- What you can do after
- Apply the DOM method to register multiple handlers for specified events.
Read how Secrets of the JavaScript Ninja, Second Edition explains addEventListener →
Also covered in
- Software Engineering for Data ScientistsIn early access (MEAP)
- Build a Frontend Web Framework (From Scratch)
- D3.js in Action, Third Edition
- Pro Angular 16
- Secrets of the JavaScript Ninja, Third EditionIn early access (MEAP)
What to know first
- Document Object ModelThe Document Object Model is a platform-independent programming interface that represents a document as a structured tree of nodes and provides ways to access and modify its content and structure.
- DOM elementA DOM element is an object representing an element node in a document tree, with properties such as its type, attributes, content, and children.
- handlerA handler is a software routine or component invoked to process an event, request, message, or other input.
Related concepts
- event-handler registrationuses · Event-handler registration is the association of a handler with an event target or type so it can run when that event occurs.
- buttonuses · A button is an interactive user-interface control that a user can activate to initiate an action or select an option.
- handleruses · A handler is a software routine or component invoked to process an event, request, message, or other input.
- feature detectionused by · Feature detection is the practice of testing whether a runtime environment supports a particular capability.
- on()alternative to · on() is a D3 selection method that registers an event listener for a specified event type and callback function.
Questions about addEventListener
What is addEventListener?
addEventListener is a method that registers a callback to be invoked when a specified event is dispatched to an event target.
Which Manning books explain addEventListener?
Vanilla Web, React Quickly, Second Edition and Secrets of the JavaScript Ninja, Second Edition.
What should I know before learning addEventListener?
Manning books that teach addEventListener usually introduce Document Object Model, DOM element and handler first.
What is the difference between addEventListener and on()?
addEventListener is a method that registers a callback to be invoked when a specified event is dispatched to an event target. on() is a D3 selection method that registers an event listener for a specified event type and callback function.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.


