Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>
<script>
    var e = document.createEvent("event");
    e.initEvent("foo", false, false);
    document.body.addEventListener("foo", function(e) {
       console.log("foo event fired at body.")
    });
    document.body.dispatchEvent(e);
  
    // reuse event.
    e.initEvent("bar", true, true);
    if (e.type === "bar")
      alert("Event can be reused by calling initEvent() after dispatching it.");
    else
      alert("Event CANNOT be reused by calling initEvent() after dispatching it.");
</script>
</body>
</html>
Output 300px

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers