Favorites

DOM EventTarget.addEventListener() Method

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
EventTarget.addEventListener()
DOM EventTarget MethodThis method is supported by all modern browsers.
Updated 28th November 2026

The addEventListener() method runs a function whenever a given event, such as a click or key press, happens on an element, the document or the window.

Description

The addEventListener() method of the EventTarget interface sets up a function that is called whenever the specified event is delivered to the target. Targets include elements, the document, the window and other objects that support events.

Unlike onclick and similar properties, you can add several listeners for the same event, and they run in the order they were added. The options object controls how the listener works: once: true removes it after the first call, passive: true promises not to call preventDefault() (which helps scrolling performance), and signal lets you remove it with an AbortController.

To remove a listener, call removeEventListener() with the same type and the same function reference, so avoid anonymous functions if you need to remove it later. Adding one listener to a parent and checking event.target, known as event delegation, is often simpler than adding listeners to many children.

Syntax

target.addEventListener(type, listener)
target.addEventListener(type, listener, options)

Parameters

  • typeThe name of the event to listen for, such as "click" or "input".
  • listenerThe function to call when the event happens. It receives an Event object.
  • optionsOptional. An object with once, passive, capture and signal settings, or true to use the capture phase.

Return Value

None (undefined).

Example

<button id="btn" type="button">Click me</button>
const btn = document.getElementById('btn');
let count = 0;

btn.addEventListener('click', event => {
  count++;
  console.log('Clicked', count, 'time(s) on', event.target.id);
});

btn.addEventListener('click', () => console.log('Runs only once'), { once: true });

btn.click();   // simulate two clicks
btn.click();

Browser Support

The following information will show you the current browser support for the EventTarget.addEventListener() method. Hover over a browser icon to see the version that first introduced support for this method.

This method is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee