Custom Events in JavaScript |

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

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

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


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

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.