Web APIs
CustomEvent()
Constructs a named event with optional detail and inherited EventInit settings.
Formal Syntax & Structure
javascript syntaxjavascript
new CustomEvent(type, options?)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| type | string | Event type. |
| options | object | Optional detail and event settings. |
Return Value
CustomEvent
New event object.
Working Example
Example Snippetjavascript
const p=document.createElement("div"),b=document.createElement("button");p.append(b);p.addEventListener("stock-change",e=>console.log(e.detail.qty));b.dispatchEvent(new CustomEvent("stock-change",{detail:{qty:4},bubbles:true}));