Event()
The Event() constructor creates a new Event object. An event created in this way is called a synthetic event, as opposed to an event fired by the browser, and can be dispatched by a script.
Syntax
new Event(typeArg)
new Event(typeArg, eventInit);
Values
typeArg-
This is a string representing the name of the event.
eventInitOptional-
This is an object with the following optional fields:
bubblesOptional-
A boolean value indicating whether the event bubbles. The default is
false. cancelableOptional-
A boolean value indicating whether the event can be cancelled. The default is
false. composedOptional-
A boolean value indicating whether the event will trigger listeners outside of a shadow root (see
Event.composedfor more details). The default isfalse.
Example
// create a look event that bubbles up and cannot be canceled
const evt = new Event("look", {"bubbles":true, "cancelable":false});
document.dispatchEvent(evt);
// event can be dispatched from any element, not only the document
myDiv.dispatchEvent(evt);
Specifications
| Specification |
|---|
| DOM Standard # ref-for-dom-event-event |
Browser compatibility
BCD tables only load in the browser