Event()
The Event() constructor creates a new Event.
Syntax
new Event(typeArg[, eventInit]);
Values
typeArg-
This is a
DOMStringrepresenting the name of the event. -
eventInitOptional -
This is an
EventInitdictionary, having 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 (DOM) # ref-for-dom-event-event |
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 | |
Event |
15 |
12 |
11 |
No |
11.6 |
6 |
≤37 |
18 |
14 |
12 |
6 |
1.0 |
See also
© 2005–2021 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/Event/Event