Skip to content

Latest commit

 

History

History

custom-events

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

Table of Contents generated with DocToc

CustomEvent

It provides an interface to send your own custom events to a DOM element. You can create a new event with the following:

var event = new CustomEvent('myEvent');

To 'fire' or dispatch the custom event to a DOM object, you should use the method dispatchEvent.

It also lets you specify custom properties to the Event object like this:

var event = new CustomEvent('myEvent', {
  detail: 'my detail for this event'
});

var listener = function(event) {
    console.log(event.detail); // prints 'my detail for this event'
}

Take in consideration that the detail property of the second argument of the constructor is the only one allowed to pass data, any other property will not be added to the fired Event object.

Compatibility

It's supported by the majority of browsers but lacks support on older IE versions. img* Source: caniuse.com

Polyfill

There's a polyfill used to add feature on older browsers.