Skip to content

Function: dispatchCustomEvent()

ts
function dispatchCustomEvent<T>(
   target, 
   eventName, 
   detail?): boolean;

Dispatches a custom event with optional detail data.

Type Parameters

Type ParameterDescription
TThe event detail type.

Parameters

ParameterTypeDescription
targetEventTargetThe target element.
eventNamestringThe event name.
detail?TThe 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

Released under the MIT License.