EventTarget - Web APIs | MDN

archived 21 Apr 2024 23:25:21 UTC
Get real-time assistance with your coding queries. Try AI Help now!

EventTarget

The EventTarget interface is implemented by objects that can receive events and may have listeners for them. In other words, any target of events implements the three methods associated with this interface.
Element, and its children, as well as Document and Window, are the most common event targets, but other objects can be event targets, too. For example IDBRequest, AudioNode, and AudioContext are also event targets.
Many event targets (including elements, documents, and windows) also support setting event handlers via onevent properties and attributes.

#Constructor

EventTarget()
Creates a new EventTarget object instance.

#Instance methods

EventTarget.addEventListener()
Registers an event handler of a specific event type on the EventTarget.
EventTarget.removeEventListener()
Removes an event listener from the EventTarget.
EventTarget.dispatchEvent()
Dispatches an event to this EventTarget.

#Specifications

Specification
DOM Standard
# interface-eventtarget

#Browser compatibility

Report problems with this compatibility data on GitHub
desktopmobileserver
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
Deno
Node.js
EventTarget
EventTarget() constructor
addEventListener
Form with options object supported (third parameter can be either options or a Boolean, for backwards compatibility)
options.capture parameter
options.once parameter
options.passive parameter
options.passive parameter defaults to true for touchstart and touchmove events
options.passive parameter defaults to true for wheel and mousewheel events
options.signal parameter
useCapture parameter is optional
dispatchEvent
removeEventListener
Form with options object supported (third parameter can be either options or a Boolean, for backwards compatibility)
useCapture parameter is optional

Legend

Tip: you can click/tap on a cell for more information.
Full supportFull support
Partial supportPartial support
No supportNo support
Compatibility unknownCompatibility unknown
See implementation notes.
Has more compatibility info.
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.

#See also

0%
10%
20%
30%
40%
50%
60%
70%
80%
90%
100%