# Custom Events in JavaScript | kirupa.com

**URL:** <https://forum.kirupa.com/t/custom-events-in-javascript-kirupa-com/539246>\
**Category:** programming\
**Created:** [February 13, 2015, 6:59am UTC](https://forum.kirupa.com/t/custom-events-in-javascript-kirupa-com/539246 "2015-02-13T06:59:42Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![kirupa](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/kirupa/32/11616_2.png) [@kirupa](https://forum.kirupa.com/u/kirupa)\
**Post date:** [February 13, 2015, 6:59am UTC](https://forum.kirupa.com/t/custom-events-in-javascript-kirupa-com/539246/1 "2015-02-13T06:59:43Z")

</div>

by [kirupa](http://www.kirupa.com/me/index.htm) | 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](http://www.kirupa.com/html5/custom_events_js.htm)

---

<div class="post-metadata">

**Author:** ![senocular](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/senocular/32/7217_2.png) [@senocular](https://forum.kirupa.com/u/senocular)\
**Post date:** [February 13, 2015, 1:01pm UTC](https://forum.kirupa.com/t/custom-events-in-javascript-kirupa-com/539246/2 "2015-02-13T13:01:11Z")

</div>

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

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

```

and

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

```

The “Conclusionn” header is having the opposite problem 😉

---

<div class="post-metadata">

**Author:** ![kirupa](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/kirupa/32/11616_2.png) [@kirupa](https://forum.kirupa.com/u/kirupa)\
**Post date:** [February 13, 2015, 6:00pm UTC](https://forum.kirupa.com/t/custom-events-in-javascript-kirupa-com/539246/3 "2015-02-13T18:00:37Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![kirupa](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/kirupa/32/11616_2.png) [@kirupa](https://forum.kirupa.com/u/kirupa)\
**Post date:** [February 14, 2015, 2:05am UTC](https://forum.kirupa.com/t/custom-events-in-javascript-kirupa-com/539246/4 "2015-02-14T02:05:29Z")

</div>

It should be fixed now 😄

---

<div class="post-metadata">

**Author:** ![ollie-w](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/ollie-w/32/8435_2.png) [@ollie-w](https://forum.kirupa.com/u/ollie-w)\
**Post date:** [May 22, 2017, 8:03pm UTC](https://forum.kirupa.com/t/custom-events-in-javascript-kirupa-com/539246/5 "2017-05-22T20:03:32Z")

</div>

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.
