Skip to content

Instantly share code, notes, and snippets.

@sTiLL-iLL
Last active December 20, 2015 14:29
Show Gist options
  • Save sTiLL-iLL/6146597 to your computer and use it in GitHub Desktop.
Save sTiLL-iLL/6146597 to your computer and use it in GitHub Desktop.
custom eventing
//create event
var minE = new CustomEvent("yourEventName", {
detail: {
"key": value
},
bubbles: true,
cancelable: true
});
//add handler
targetElement.addEventListener("yourEventName", function(e) {
alert("event = ", e);
alert("event data = ", e.detail);
});
// trigger
targetElement.dispatchEvent(minE);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment