Movatterモバイル変換


[0]ホーム

URL:


  1. Web
  2. Web APIs
  3. Event
  4. Event()

Event: Event() constructor

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since ⁨July 2015⁩.

Note: This feature is available inWeb Workers.

TheEvent() constructor creates a newEvent object. An event created in this way is called asynthetic event, as opposed to an event fired by the browser, and can bedispatched by a script.

Syntax

js
new Event(type)new Event(type, options)

Values

type

A string with the name of the event.

optionsOptional

An object with the following properties:

bubblesOptional

A boolean value indicating whether the event bubbles. The default isfalse.

cancelableOptional

A boolean value indicating whether the event can be cancelled. Thedefault isfalse.

composedOptional

A boolean value indicating whether the event will trigger listenersoutside of a shadow root (seeEvent.composed for more details). Thedefault isfalse.

Return value

A newEvent object.

Example

js
// create a look event that bubbles up and cannot be canceledconst evt = new Event("look", { bubbles: true, cancelable: false });document.dispatchEvent(evt);// event can be dispatched from any element, not only the documentmyDiv.dispatchEvent(evt);

Specifications

Specification
DOM
# ref-for-dom-event-event

Browser compatibility

See also

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp