Web/API/Event/Event

From Get docs
< Web/API‎ | Event


The Event() constructor creates a new Event.

Syntax

new Event(typeArg[, eventInit]);

Values

typeArg
This is a DOMString representing the name of the event.
eventInit Optional
This is an EventInit dictionary, having the following optional fields:
bubbles Optional
A Boolean indicating whether the event bubbles. The default is false.
cancelable Optional
A Boolean indicating whether the event can be cancelled. The default is false.
composed Optional
A Boolean indicating whether the event will trigger listeners outside of a shadow root (see Event.composed for more details). The default is false.

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 Status Comment
DOMThe definition of 'Event()' in that specification. Living Standard Initial definition

Browser compatibility

Update compatibility data on GitHub

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
Event() constructor Chrome

Full support 15

Edge

Full support 12

Firefox

Full support 11

IE

No support No

Opera

Full support 11.6

Safari

Full support 6

WebView Android

Full support ≤37

Chrome Android

Full support 18

Firefox Android

Full support 14

Opera Android

Full support 12

Safari iOS

Full support 6

Samsung Internet Android

Full support 1.0

Legend

Full support  
Full support
No support  
No support


See also

Event() by Mozilla Contributors is licensed under CC-BY-SA 2.5.