Created
July 20, 2012 00:23
-
-
Save lean8086/3147862 to your computer and use it in GitHub Desktop.
Creating, triggering and listening a custom event
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Defining the custom event | |
var customEvent = (function () { | |
"use strict"; | |
// Create a generic event | |
var e = document.createEvent("Event"); | |
// Define the custom event name | |
e.initEvent("custom", true, true); | |
// Grab event to trigger | |
return e; | |
}()); | |
// Trigger the event | |
document.dispatchEvent(customEvent); | |
// Listen for the event | |
document.addEventListener("custom", function () { ... }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment