CustomEvent

A browser event type you create and name yourself, which carries any data you like in its detail property.

In more detail

new CustomEvent('cart-add', { detail: item, bubbles: true, cancelable: true }) is dispatched like any other event. Components can announce what happened without knowing who is listening.

Example

el.dispatchEvent(new CustomEvent('cart-add', { detail: { id: 'prod-99', qty: 2 }, bubbles: true }))

Related terms

Taught in

References