Favorites

DOM EventTarget.dispatchEvent() Method

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
EventTarget.dispatchEvent()
DOM EventTarget MethodThis method is supported by all modern browsers.
Updated 28th November 2026

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 Event or CustomEvent object to send.

Return Value

false if the event is cancelable and a listener called preventDefault(), otherwise true.

Example

<div id="el">Target</div>
const el = document.getElementById('el');
el.addEventListener('ping', e => console.log('got', e.type, e.detail));
const ok = el.dispatchEvent(new CustomEvent('ping', { detail: 42, cancelable: true }));
console.log('not cancelled:', ok);

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.

This method is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee