EventTarget.addEventListener(type, listener) registers a function (or handleEvent object) that runs when that event type is delivered to the target. Per MDN, it is the recommended way to listen for events — returns undefined.
Pass the required arguments shown below. Check return values and browser support before you rely on the result.
Syntax
Call target.addEventListener. Start with this line.
JavaScript
target.addEventListener(type, listener, options?)
Call
What it does
target.addEventListener(type, listener, options?)
Primary signature.
target.addEventListener(...)
Call with the arguments your case needs.
Built into the browser. Call addEventListener(...) on an EventTarget (or Element, Document, Window, …) — no import required.
Library declarations
JavaScript
target.addEventListener(type, listener, options?)
Parameters
Parameter
Description
type
Required. Event name string (e.g. "click")
Good for setup. One-shot init or “first interaction” handlers.
Example 4 — this Binding
In a regular function listener, this is the target element.
JavaScript
const button = document.querySelector("#demoBtn");
button.addEventListener("click", function (e) {
console.log(this.id); // "demoBtn"
console.log(e.currentTarget === this); // true
});
// Arrow functions do NOT bind this to the element
Create a controller.new AbortController() owns a signal.
Pass the signal. Third argument: { signal: controller.signal }.
Abort when done.controller.abort() removes the listener.
Handy cleanup. One abort can tear down many listeners that share the signal.
Compatibility
Browser Support
EventTarget.addEventListener() is marked Baseline Widely available on MDN (since July 2015). It is a browser Web API (also available in Web Workers). Some options such as signal have varying support in older browsers.
✓ Baseline · Widely available
EventTarget.addEventListener()
Supported across modern Chrome, Firefox, Safari, and Edge for registering event listeners.
98%Browser support
Google ChromeSupported · Desktop & Mobile
Full support
Mozilla FirefoxSupported · Desktop & Mobile
Full support
Apple SafariSupported · macOS & iOS
Full support
Microsoft EdgeSupported · Chromium
Full support
Internet ExplorerNo native support · Use a polyfill
Polyfill
OperaSupported · Modern versions
Full support
Samsung InternetSupported · Android
Full support
Android WebViewSupported · Modern WebView
Full support
addEventListener()Excellent
Bottom line: Safe for production. Prefer addEventListener over onXYZ properties; use removeEventListener or AbortSignal for cleanup.
Frequently Asked Questions
It registers a function (or an object with handleEvent) to run when the given event type is delivered to that target — for example a button click or a custom event on new EventTarget().
No. MDN marks EventTarget.addEventListener() as Baseline Widely available (since July 2015). It is not Deprecated, Experimental, or Non-standard. Some options (for example signal) have varying support across older browsers.
You can attach many handlers for the same event, choose capture vs bubble, use options like once and signal, and it works on any EventTarget — not only HTML elements.
The same function or handleEvent object is not added twice for the same target and type. Two separately created anonymous functions count as different listeners.
With { once: true }, the listener runs at most once and is then removed automatically.
Call removeEventListener with the same type and the same function reference, or pass { signal } from an AbortController and call abort().