Function: dispatchCustomEvent()
ts
function dispatchCustomEvent<T>(
target,
eventName,
detail?): boolean;Dispatches a custom event with optional detail data.
Type Parameters
| Type Parameter | Description |
|---|---|
T | The event detail type. |
Parameters
| Parameter | Type | Description |
|---|---|---|
target | EventTarget | The target element. |
eventName | string | The event name. |
detail? | T | The detail payload. |
Returns
boolean
true when the event was not canceled.
Example
ts
const el = document.createElement('div')
document.body.appendChild(el)
el.addEventListener('my-event', (e) => console.log('fired', e.detail))
dispatchCustomEvent(el, 'my-event', { data: 1 })Since
1.0.0