DOM CustomEvent Interface
CustomEvent lets you create your own events with extra data in a detail property, and dispatch them on any element or EventTarget.
Description
The CustomEvent interface represents an event created by your own code, carrying any data you like in its detail property. Create one with new CustomEvent(type, options) and send it with dispatchEvent(); listeners are added with addEventListener() as for built-in events.
Custom events let separate parts of an application, or web components, communicate without knowing about each other. Set bubbles: true if ancestors should be able to listen for it.
The detail value is passed by reference, so listeners receive the same object; avoid changing it in one listener if others also use it. Event names for custom events can be any string, but using a prefix or namespace, such as "cart:add", helps avoid clashes with built-in events and other libraries. Setting cancelable: true lets listeners call preventDefault(), and dispatchEvent() then returns false so the sender can react.
Inheritance
CustomEvent inherits properties and methods from Event.
Properties
| Name | Description |
|---|---|
CustomEvent.detail | The detail property of a CustomEvent holds the data passed when the event was created. |
Example
Browser Support
The following information will show you the current browser support for the CustomEvent interface. Hover over a browser icon to see the version that first introduced support for this interface.
Desktop





Tablets & Mobile





