dispatchEvent() is how you fire an event on any EventTarget. Create an Event or CustomEvent, then dispatch it to run listeners registered with addEventListener(). Learn the synchronous return value, preventDefault, isTrusted, five examples, and try-it labs.
01
Kind
Instance method
02
Input
Event object
03
Returns
true / false
04
Timing
Synchronous
05
isTrusted
false
06
Workers
Supported
Fundamentals
Introduction
Listening alone is not enough — something must deliver the event. Native clicks are fired by the browser. Your own app events are fired with dispatchEvent().
First create the event (new Event("ping") or new CustomEvent("change", { detail })), then call target.dispatchEvent(event). Matching listeners run right away, before the next line of your code.
💡
Last step to fire
MDN: calling dispatchEvent() is the last step. The event must already be created and initialized with a constructor.
dispatchEvent sends the event through the normal processing rules (including capture and bubble on DOM nodes). For a plain new EventTarget(), listeners on that object simply run in order.
Event.target becomes the object you called dispatchEvent on.
Handlers run on a nested call stack — they finish before dispatchEvent returns.
Exceptions in handlers are reported as uncaught; they do not bubble to your caller.
Synthetic events have isTrusted === false.
Foundation
📝 Syntax
General form of EventTarget.dispatchEvent:
JavaScript
dispatchEvent(event)
Parameters
event — the Event (or CustomEvent) to dispatch. Its target will be set to this EventTarget.
Return value
false — the event is cancelable and a listener called preventDefault().
EventTarget.dispatchEvent() is Baseline Widely available across modern browsers and has been part of the DOM event model for a long time. It is also available in Web Workers.
✓ Baseline · Widely available
EventTarget.dispatchEvent()
Safe for production. Create Event/CustomEvent first, then dispatch synchronously to your listeners.
UniversalWidely available
Google ChromeAll versions · Desktop & Mobile
Full support
Mozilla FirefoxAll versions · Desktop & Mobile
Full support
Apple SafariAll versions · macOS & iOS
Full support
Microsoft EdgeAll versions · Chromium & Legacy
Full support
Internet ExplorerIE 6+ · Legacy environments
Full support
OperaAll modern versions
Full support
dispatchEvent()Excellent
Bottom line: Use dispatchEvent to fire app events. Check the boolean return for cancelable flows, and remember isTrusted is false for synthetic events.
Wrap Up
Conclusion
dispatchEvent() is the firing step of the EventTarget API: build an Event or CustomEvent, dispatch it, and listeners run immediately. Use the boolean return with cancelable events when listeners may call preventDefault().
Create events with Event / CustomEvent constructors
Match type strings carefully with listeners
Use detail for structured payloads
Check the return value for cancelable workflows
Remember delivery is synchronous
❌ Don’t
Dispatch before the event is constructed
Expect isTrusted to be true for synthetic events
Assume handler errors bubble to your call site
Use dispatchEvent to fake trusted user gestures for restricted APIs
Forget cancelable: true when you need preventDefault
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about dispatchEvent()
Fire events synchronously on any EventTarget.
5
Core concepts
🔥01
Fire
dispatchEvent(evt)
API
⏱02
Sync
listeners first
Timing
📦03
detail
CustomEvent
Data
✅04
Return
true / false
Cancel
🔒05
isTrusted
false
Synthetic
❓ Frequently Asked Questions
EventTarget.dispatchEvent(event) sends an Event to that target and runs matching listeners immediately (synchronously). Create the event first with new Event() or new CustomEvent().
Yes. Unlike most native browser events that are queued, dispatchEvent runs applicable listeners before it returns. Code after dispatchEvent runs only after those listeners finish.
It returns false if the event is cancelable and a listener called preventDefault(). Otherwise it returns true.
Native browser events have isTrusted true. Events you fire with dispatchEvent have isTrusted false — they are synthetic.
Yes. When you call dispatchEvent, Event.target is initialized to the EventTarget you called it on.
A TypeError is thrown if the event type was not specified during initialization.
Did you know?
Even on a DOM element, an event you fire with dispatchEvent still gets isTrusted: false. Real user clicks stay true — that is how browsers tell “synthetic” from “native.”