DOM Custom Events

What DOM Custom Events Are

DOM custom events are developer-created events that are not already built into the DOM.

How to Create DOM Custom Events

DOM custom events can be created by using either the Event constructor or the CustomEvent constructor. In either constructor, the first parameter is the type parameter, which is the name of the event. The CustomEvent type is case-sensitive, whereas the Event type is not. The second parameter is the options parameter, which is where the bubbles, cancelable, and composed properties are set. An additional property, which can only be set in the CustomEvent constructor, is details. The details property passes data to the event listener.

Why DOM Custom Events are Used

DOM custom events are used when built-in events don't have the functionality a developer wants.

Summary

DOM custom events are events that a developer creates that are not built into the DOM. DOM custom events are created using the Event constructor or the CustomEvent constructor. The parameters that are set when using either constructor are type and options. Type sets the event name, and options sets event properties.