The Event interface represents any event which takes place in the DOM; some are user-generated (such as mouse or keyboard events), while others are generated by APIs (such as events that indicate an animation has finished running, a video has been paused, and so forth). While events are usually triggered by such "external" sources, they can also be triggered programmatically, such as by calling the HTMLElement.click() method of an element, or by defining the event, then sending it to a specified target using EventTarget.dispatchEvent(). There are many types of events, some of which use other interfaces based on the main Event interface. Event itself contains the properties and methods which are common to all events.
Many DOM elements can be set up to accept (or "listen" for) these events, and execute code in response to process (or "handle") them. Event-handlers are usually connected (or "attached") to various HTML elements (such as <button>, <div>, <span>, etc.) using EventTarget.addEventListener(), and this generally replaces using the old HTML event handler attributes. Further, when properly added, such handlers can also be disconnected if needed using removeEventListener(). Note that one element can have several such handlers, even for the exact same event, particularly if separate, independent code modules attach them, each for its own independent purposes (for example, a webpage with an advertising-module and statistics-module both monitoring video-watching). When there are many nested elements, each with its own handler(s), event processing can become very complicated -- especially where a parent element receives the very same event as its child elements because "spatially" they overlap so the event technically occurs in both, and the processing order of such events depends on the Event bubbling and capture settings of each handler triggered.
Below is a list of interfaces which are based on the main Event interface, with links to their respective documentation in the MDN API reference. Note that all event interfaces have names which end in "Event".
AnimationEventAudioProcessingEventBeforeInputEventBeforeUnloadEventBlobEventClipboardEventCloseEventCompositionEventCSSFontFaceLoadEventCustomEventDeviceLightEventDeviceMotionEventDeviceOrientationEventDeviceProximityEventDOMTransactionEventDragEventEditingBeforeInputEventErrorEventFetchEventFocusEventGamepadEventHashChangeEventIDBVersionChangeEventInputEventKeyboardEventMediaStreamEventMessageEventMouseEventMutationEventOfflineAudioCompletionEventPageTransitionEventPaymentRequestUpdateEventPointerEventPopStateEventProgressEventRelatedEventRTCDataChannelEventRTCIdentityErrorEventRTCIdentityEventRTCPeerConnectionIceEventSensorEventStorageEventSVGEventSVGZoomEventTimeEventTouchEventTrackEventTransitionEventUIEventUserProximityEventWebGLContextEventWheelEventEvent()Event object, returning it to the caller.Event.bubbles Read only
Event.cancelBubbleEvent.stopPropagation(). Setting its value to true before returning from an event handler prevents propagation of the event.Event.cancelable Read only
Event.composed Read only
Event.currentTarget Read only
Event.deepPath
Array of DOM Nodes through which the event has bubbled.Event.defaultPrevented Read only
event.preventDefault() has been called on the event.Event.eventPhase Read only
Event.explicitOriginalTarget Read only
Event.originalTarget Read only
Event.returnValueEvent.preventDefault() and Event.defaultPrevented instead, but you can use returnValue if you choose to do so.Event.srcElement
Event.target, which is starting to be supported in some other browsers for web compatibility purposes.Event.target Read only
Event.timeStamp Read only
DOMHighResTimeStamp instead.Event.type Read only
Event.isTrusted Read only
Event.scoped Read only
Boolean indicating whether the given event will bubble across through the shadow root into the standard DOM. This property has been renamed to composed.Event.createEvent()
Creates a new event, which must then be initialized by calling its initEvent() method.
Event.composedPath()ShadowRoot.mode closed.Event.initEvent()
Event.preventDefault()Event.stopImmediatePropagation()Event.stopPropagation()Event.getPreventDefault()
Event.defaultPrevented. Use Event.defaultPrevented instead.Event.preventBubble() Obsolete since Gecko 24
event.stopPropagation instead.Event.preventCapture() Obsolete since Gecko 24
event.stopPropagation instead.| Specification | Status | Comment |
|---|---|---|
| DOM The definition of 'Event' in that specification. | Living Standard |
| Desktop | ||||||
|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | |
| Basic support | Yes | Yes | Yes | Yes | Yes | Yes |
Event() constructor |
15 | Yes | 11 | No | 11.6 | 6 |
bubbles |
Yes | ? | ? | ? | Yes | ? |
cancelBubble |
Yes
|
Yes | 53
|
Yes | Yes
|
Yes |
cancelable |
Yes | ? | ? | ? | Yes | ? |
composed |
53 | ? | 52 | ? | 40 | ? |
composedPath |
53
|
No | 52 | No | 40
|
10 |
createEvent |
No | ? | ? | ? | No | ? |
currentTarget |
Yes | Yes | Yes | 9
|
Yes | 10 |
defaultPrevented |
18 | Yes | 6 | 9 | 11 | 5 |
eventPhase |
45 | ? | ? | ? | 32 | ? |
explicitOriginalTarget
|
No | No | Yes | No | No | No |
getPreventDefault
|
No | ? | ? — 59
|
? | No | ? |
initEvent
|
Yes | Yes | 17
|
Yes | Yes | Yes |
isTrusted |
46
|
Yes | Yes | No
|
33
|
No |
originalTarget
|
No | No | Yes | No | No | No |
preventBubble
|
No | ? | ? — 24 | ? | No | ? |
preventCapture
|
No | ? | ? — 24 | ? | No | ? |
preventDefault |
Yes | Yes | Yes | 9 | Yes | Yes |
returnValue
|
Yes | Yes | 63 | 6 | Yes | Yes |
srcElement
|
Yes | Yes | 62 | Yes | Yes | Yes |
stopImmediatePropagation |
6 | Yes | 10 | 9 | 15 | 5 |
stopPropagation |
Yes | Yes | Yes | 9 | Yes | Yes |
target |
Yes | Yes | Yes | Yes | Yes | Yes |
timeStamp |
49
|
Yes | Yes
|
Yes
|
36
|
Yes |
type |
45 | ? | ? | ? | 32 | ? |
| Mobile | |||||||
|---|---|---|---|---|---|---|---|
| Android webview | Chrome for Android | Edge Mobile | Firefox for Android | Opera for Android | iOS Safari | Samsung Internet | |
| Basic support | Yes | Yes | Yes | Yes | Yes | Yes | ? |
Event() constructor |
Yes | 18 | Yes | 14 | 11.6 | 6 | ? |
bubbles |
Yes | Yes | ? | ? | Yes | ? | ? |
cancelBubble |
Yes
|
Yes
|
Yes | 53
|
Yes
|
Yes | ? |
cancelable |
Yes | Yes | ? | ? | Yes | ? | ? |
composed |
53 | 53 | ? | 52 | 40 | ? | ? |
composedPath |
53
|
53
|
No | 52 | 40
|
10 | ? |
createEvent |
No | No | ? | ? | No | ? | ? |
currentTarget |
Yes | Yes | Yes | Yes | Yes | 10 | ? |
defaultPrevented |
Yes | 18 | Yes | 6 | 11 | 5 | ? |
eventPhase |
45 | 45 | ? | ? | 32 | ? | ? |
explicitOriginalTarget
|
No | No | No | Yes | No | No | ? |
getPreventDefault
|
No | No | ? | ? — 59
|
No | ? | ? |
initEvent
|
Yes | Yes | Yes | 17
|
Yes | Yes | ? |
isTrusted |
46
|
46
|
Yes | Yes | 33
|
No | ? |
originalTarget
|
No | No | No | Yes | No | No | ? |
preventBubble
|
No | No | ? | ? — 24 | No | ? | ? |
preventCapture
|
No | No | ? | ? — 24 | No | ? | ? |
preventDefault |
Yes | Yes | Yes | Yes | Yes | Yes | ? |
returnValue
|
Yes | Yes | Yes | 63 | Yes | Yes | ? |
srcElement
|
Yes | Yes | Yes | 62 | Yes | Yes | ? |
stopImmediatePropagation |
Yes | 18 | Yes | 10 | 15 | 5 | ? |
stopPropagation |
Yes | Yes | Yes | Yes | Yes | Yes | ? |
target |
Yes | Yes | Yes | Yes | Yes | Yes | ? |
timeStamp |
49
|
49
|
Yes | Yes
|
36
|
Yes | ? |
type |
45 | 45 | ? | ? | 32 | ? | ? |
© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/Event