Baseline Widely available
Note: This feature is available in Web Workers.
The Event()
constructor creates a new Event
object. An event created in this way is called a synthetic event, as opposed to an event fired by the browser, and can be dispatched by a script.
new Event(type)
new Event(type, options)
Values
type
A string with the name of the event.
options
Optional
An object with the following properties:
bubbles
Optional
A boolean value indicating whether the event bubbles. The default is false
.
cancelable
Optional
A boolean value indicating whether the event can be cancelled. The default is false
.
composed
Optional
A boolean value indicating whether the event will trigger listeners outside of a shadow root (see Event.composed
for more details). The default is false
.
A new Event
object.
// 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 Browser compatibility See also
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4