DOM EventTarget.dispatchEvent() Method
The dispatchEvent() method sends an event to an element or other target, running its listeners straight away.
Description
The dispatchEvent() method sends an Event to the target, calling the matching listeners synchronously, in order, before it returns. It's used with CustomEvent to create your own events, and to simulate built-in ones. Events created this way have isTrusted set to false, and don't trigger the browser's default actions, such as following a link.
Because dispatchEvent() is synchronous, any changes made by listeners are visible immediately after it returns, unlike events triggered by the browser, which are processed when the current code finishes. Exceptions thrown by listeners are reported to the console but don't stop other listeners from running, and don't reach the code that called dispatchEvent().
To make an event reach ancestors of the target, create it with bubbles: true. Dispatching a built-in event type, such as new Event('input', { bubbles: true }), is a common way to let other code know that a field's value was changed by script.
Syntax
target.dispatchEvent(event)Parameters
- eventThe
EventorCustomEventobject to send.
Return Value
false if the event is cancelable and a listener called preventDefault(), otherwise true.
Example
Browser Support
The following information will show you the current browser support for the EventTarget.dispatchEvent() method. Hover over a browser icon to see the version that first introduced support for this method.
Desktop





Tablets & Mobile





