Skip to content

Instantly share code, notes, and snippets.

@JacobWay
Last active April 11, 2016 08:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JacobWay/ad047e4706a09cf07599096e9879eef1 to your computer and use it in GitHub Desktop.
Save JacobWay/ad047e4706a09cf07599096e9879eef1 to your computer and use it in GitHub Desktop.
The older approach to creating events uses APIs inspired by JAVA
// create event
var evt = document.createEvent("Event");
// initializing the event
evt.initEvent("anyName", true, true);
// add event handler
document.addEventListener("anyName", function(e){
// your handler logic
console.log("e.target: ", e.target);
}, false);
// dispatch the event
document.dispatchEvent(evt);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment