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 isfalse
. cancelable
Optional- A
Boolean
indicating whether the event can be cancelled. The default isfalse
. composed
Optional- A
Boolean
indicating whether the event will trigger listeners outside of a shadow root (seeEvent.composed
for 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 | Status | Comment |
---|---|---|
DOMThe definition of 'Event()' in that specification. | Living Standard | Initial definition |
Browser compatibility
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
Update compatibility data on GitHub
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
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.