Movatterモバイル変換


[0]ホーム

URL:


MDN Web Docs

EventTarget: dispatchEvent() method

BaselineWidely available

Note: This feature is available inWeb Workers.

ThedispatchEvent() method of theEventTarget sends anEvent to the object, (synchronously) invoking the affectedevent listeners in the appropriate order. The normal event processingrules (including the capturing and optional bubbling phase) also apply to eventsdispatched manually withdispatchEvent().

CallingdispatchEvent() is the last step tofiring an event. The eventshould have already been created and initialized using anEvent() constructor.

Note:When calling this method, theEvent.target property is initialized to the currentEventTarget.

Unlike "native" events, which are fired by the browser and invoke event handlersasynchronously via theevent loop,dispatchEvent() invokes event handlerssynchronously. All applicable eventhandlers are called and return beforedispatchEvent() returns.

Syntax

js
dispatchEvent(event)

Parameters

event

TheEvent object to dispatch. ItsEvent.target property will be set to the currentEventTarget.

Return value

false ifevent is cancelable, and at least one of the event handlers which receivedevent calledEvent.preventDefault(). Otherwisetrue.

Exceptions

InvalidStateErrorDomException

Thrown if the event's type was not specified during event initialization.

Warning:Exceptions thrown by event handlers are reported as uncaught exceptions. The eventhandlers run on a nested callstack; they block the caller until they complete, butexceptions do not propagate to the caller.

Example

Specifications

Specification
DOM
# ref-for-dom-eventtarget-dispatchevent③

Browser compatibility

See also

Help improve MDN

Learn how to contribute.

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp