Event: Event() constructor - Web APIs | MDN
Syntax
js
new Event(type)
new Event(type, options)
Values
type-
A string with the name of the event.
optionsOptional-
An object with the following properties:
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.
Return value
A new Event object.
Example
js
// 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 # ref-for-dom-event-event |