Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / JavaScript

EventTarget.removeEventListener — removing event listeners

removeEventListener() removes a listener by matching the event type, callback identity, and capture value on the same target.

Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support

Syntax

target.removeEventListener(type, callback[, options])

EventTarget.removeEventListener removes a listener registered through addEventListener(). It returns undefined; no match means no change.

The target, type, callback identity, and capture must match. Keep the function reference: a new function with identical code does not match. This also applies to objects with handleEvent().

options accepts a boolean or an object containing capture; the default is false. passive, once, and signal do not participate in matching. Registrations with capture: true and capture: false require separate removal.

Examples

const target = new EventTarget();
let calls = 0;
function handler() {
  calls += 1;
}

target.addEventListener("ping", handler, true);
target.removeEventListener("ping", handler, false);
target.dispatchEvent(new Event("ping"));
console.log(calls);

target.removeEventListener("ping", handler, { capture: true });
target.dispatchEvent(new Event("ping"));
console.log(calls);

Result

1
1

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources