Web APIs

EventTarget.dispatchEvent()

Try the free JavaScript compiler

Synchronously dispatches an event and returns false if canceled, otherwise true.

Formal Syntax & Structure

javascript syntaxjavascript
target.dispatchEvent(event)

Parameters & Attributes

NameTypeDescription
eventEventEvent 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");
JavaScript Reference