W3cubDocs

/Web APIs

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 XMLHttpRequest, 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

Browser compatibility

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari WebView Android Chrome Android Firefox for Android Opera Android Safari on IOS Samsung Internet
EventTarget 64 79 59 No 51 14 64 64 59 47 14 9.0
EventTarget 1 12 1 6 7
1window.EventTarget did not exist on versions of Safari before 10.1.
≤37 18 4 10.1
1window.EventTarget did not exist on versions of Safari iOS before 10.3.
1.0
addEventListener
1Before Chrome 49, the type and listener parameters were optional.
12 1 9
6–11Older versions of IE supported an equivalent, proprietary EventTarget.attachEvent() method.
7 1
1Before Chrome 49, the type and listener parameters were optional.
18Before Chrome 49, the type and listener parameters were optional.
4 10.1 1
1.0Before Samsung Internet 5.0, the type and listener parameters were optional.
dispatchEvent 4 12 2 9
6–11Older versions of IE supported an equivalent, proprietary EventTarget.fireEvent() method.
9 3.1 4 18 4 10.1 3 1.0
removeEventListener 1 12 1 9
6–11Older versions of IE supported an equivalent, proprietary EventTarget.detachEvent() method.
7 1 4.4 18 4 10.1 1 1.0

See also

© 2005–2023 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/EventTarget