Web APIs
EventTarget.dispatchEvent()
Synchronously dispatches an event and returns false if canceled, otherwise true.
Formal Syntax & Structure
javascript syntaxjavascript
target.dispatchEvent(event)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| event | Event | Event to dispatch. |
Return Value
boolean
False when canceled; true otherwise.
Working Example
Example Snippetjavascript
const t=new EventTarget();t.addEventListener("ready",()=>console.log("listener"));console.log("before");t.dispatchEvent(new Event("ready"));console.log("after");