Event extension type

The Event interface represents an event which takes place in the DOM.

An event can be triggered by the user action e.g. clicking the mouse button or tapping keyboard, or generated by APIs to represent the progress of an asynchronous task. It 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: 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.

on
Implemented types
Implementers

Constructors

Event(String type, [EventInit eventInitDict])
factory

Properties

bubbles bool
no setter
cancelable bool
no setter
cancelBubble bool
getter/setter pair
composed bool
no setter
currentTarget EventTarget?
no setter
defaultPrevented bool
no setter
eventPhase int
no setter
hashCode int
The hash code for this object.
no setterinherited
isTrusted bool
no setter
returnValue bool
getter/setter pair
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
srcElement EventTarget?
no setter
target EventTarget?
no setter
timeStamp DOMHighResTimeStamp
no setter
type String
no setter

Methods

composedPath() JSArray<EventTarget>
The composedPath() method of the Event interface returns the event's path which is an array of the objects on which listeners will be invoked. This does not include nodes in shadow trees if the shadow root was created with its ShadowRoot.mode closed.
initEvent(String type, [bool bubbles, bool cancelable]) → void
The Event.initEvent() method is used to initialize the value of an event created using Document.createEvent.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
preventDefault() → void
The preventDefault() method of the Event interface tells the that if the event does not get explicitly handled, its default action should not be taken as it normally would be.
stopImmediatePropagation() → void
The stopImmediatePropagation() method of the Event interface prevents other listeners of the same event from being called.
stopPropagation() → void
The stopPropagation() method of the Event interface prevents further propagation of the current event in the capturing and bubbling phases. It does not, however, prevent any default behaviors from occurring; for instance, clicks on links are still processed. If you want to stop those behaviors, see the Event.preventDefault method. It also does not prevent propagation to other event-handlers of the current element. If you want to stop those, see Event.stopImmediatePropagation.
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Properties

AT_TARGET int
no setter
BUBBLING_PHASE int
no setter
CAPTURING_PHASE int
no setter
NONE int
no setter