Movatterモバイル変換


[0]ホーム

URL:


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

Event: initEvent() method

Deprecated: This feature is no longer recommended. Though some browsers might still support it, it may have already been removed from the relevant web standards, may be in the process of being dropped, or may only be kept for compatibility purposes. Avoid using it, and update existing code if possible; see thecompatibility table at the bottom of this page to guide your decision. Be aware that this feature may cease to work at any time.

Note: This feature is available inWeb Workers.

TheEvent.initEvent() method is used to initialize thevalue of anevent created usingDocument.createEvent().

Events initialized in this way must have been created with theDocument.createEvent() method.This method must be called to set the eventbefore it is dispatched, usingEventTarget.dispatchEvent().Once dispatched, it doesn't do anything anymore.

Note:Do not use this method anymore as it is deprecated.Instead use specific event constructors, likeEvent().The section onCreating and dispatching events gives more information about the way to use these.

Syntax

js
initEvent(type, bubbles, cancelable)

Parameters

type

A string defining the type of event.

bubbles

A boolean value deciding whether the event should bubble up through theevent chain or not. Once set, the read-only propertyEvent.bubbleswill give its value.

cancelable

A boolean value defining whether the event can be canceled. Once set, theread-only propertyEvent.cancelable will give its value.

Return value

None.

Example

js
// Create the event.const event = document.createEvent("Event");// Create a click event that bubbles up and// cannot be canceledevent.initEvent("click", true, false);// Listen for the event.elem.addEventListener("click", (e) => {  // e.target matches elem});elem.dispatchEvent(event);

Specifications

Specification
DOM
# dom-event-initevent

Browser compatibility

See also

  • The constructor to use instead of this deprecated method:Event(). To create more specific event interfaces thanEvent, use the constructor defined for the desired event interface.

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp