Custom Events in JavaScript | kirupa.com

by kirupa | 30 December 2013

Despite the large number of events JavaScript provides out of the box for a whole bunch of scenarios, there will be times when you want to fire your own events for your own particular needs:


This is a companion discussion topic for the original entry at http://www.kirupa.com/html5/custom_events_js.htm

There are a couple of code blocks that are getting partially truncated:

var myEvent = new CustomEvent("myEventName",
    {
        'detail': Math.round(Math.rand    });

and

function doSomething(e) {Something(e) {
    alert("Event detail is: " + e.de}

The “Conclusionn” header is having the opposite problem :wink:

1 Like

The html is all sorts of broken. Let me see…

It should be fixed now :smile:

This is a nice and clear explanation of the syntax but after reading this and a couple of other articles about custom events around the web I still feel unsure of why they’re useful and in what situations it would be sensible to use one.