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

Browser compatibility

BCD tables only load in the browser

See also