EventTarget.prototype.removeEventListener
Removes an event listener previously registered with addEventListener from the EventTarget
Syntax
target.removeEventListener(type, listener, options?)Parameters
| Parameter | Type | Description |
|---|---|---|
| type | string | The event type to remove the listener for |
| listener | EventListener | Function | The handler to remove |
| options | boolean | EventListenerOptions | Options that match the addEventListener call |
Return Value
undefined
Examples
function handleClick() {
console.log('Clicked once')
btn.removeEventListener('click', handleClick)
}
const btn = document.querySelector('button')!
btn.addEventListener('click', handleClick)const handler = (e: KeyboardEvent) => console.log(e.key)
document.addEventListener('keydown', handler)
// Later:
document.removeEventListener('keydown', handler)class Component {
private handler = () => this.update()
mount() { window.addEventListener('scroll', this.handler) }
unmount() { window.removeEventListener('scroll', this.handler) }
update() { console.log('scrolled') }
}Understanding EventTarget.prototype.removeEventListener
The EventTarget.prototype.removeEventListener method in JavaScript removes an event listener previously registered with addEventListener from the EventTarget. It belongs to the EventTarget object and is one of the most widely used methods for working with eventtarget values in modern JavaScript and TypeScript applications.
The method signature is target.removeEventListener(type, listener, options?). It accepts 3 parameters: type, listener, options. When called, it returns undefined. Understanding when and how to use removeEventListener() helps you write more expressive, readable code.
Common use cases for EventTarget.prototype.removeEventListener include data transformation, input validation, API response processing, and building reusable utility functions. It works well alongside related methods like event-addeventlistener, event-dispatchevent, event-abortsignal, enabling you to chain operations together for complex data manipulation pipelines.
Browser support for EventTarget.prototype.removeEventListener is excellent across all modern browsers including Chrome, Firefox, Safari, and Edge. It is also fully supported in Node.js and Deno. For older environments, transpilation with Babel or a polyfill may be needed.
Browser Compatibility
Supported in all modern browsers (Chrome, Firefox, Safari, Edge) and Node.js. Part of the ECMAScript standard.
Related Methods
EventTarget.prototype.addEventListenerRegisters an event handler of a specific event type on the EventTarget
EventTarget.prototype.dispatchEventDispatches an event to this EventTarget, invoking the affected event listeners in the appropriate order
AbortSignalRepresents a signal object that allows you to communicate with an asynchronous operation and abort it if desired
More EventTarget Methods
Other methods in the EventTarget object
Related Tools
More EventTarget Methods
Explore JavaScript Methods
Browse our complete reference of 410 JavaScript methods with syntax, examples, and explanations.