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 in Web Workers.
The dispatchEvent() method of the EventTarget sends an Event to the object, (synchronously) invoking the affected event listeners in the appropriate order. The normal event processing rules (including the capturing and optional bubbling phase) also apply to events dispatched manually with dispatchEvent().
Calling dispatchEvent() is the last step to firing an event. The event should have already been created and initialized using an Event() constructor.
Note: When calling this method, the Event.target property is initialized to the current EventTarget.
Unlike "native" events, which are fired by the browser and invoke event handlers asynchronously via the event loop, dispatchEvent() invokes event handlers synchronously. All applicable event handlers are called and return before dispatchEvent() returns.
dispatchEvent(event)
eventThe Event object to dispatch. Its Event.target property will be set to the current EventTarget.
false if event is cancelable, and at least one of the event handlers which received event called Event.preventDefault(). Otherwise true.
InvalidStateError DomException
Thrown if the event's type was not specified during event initialization.
Warning: Exceptions thrown by event handlers are reported as uncaught exceptions. The event handlers run on a nested callstack; they block the caller until they complete, but exceptions do not propagate to the caller.
See Creating and dispatching events.
| Specification |
|---|
| DOM> # ref-for-dom-eventtarget-dispatchevent③> |
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | WebView on iOS | |
dispatchEvent |
4 | 12 | 2 | 9 | 3.1 | 18 | 4 | 10.1 | 3 | 1.0 | 4 | 3 |
© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/dispatchEvent