Created
November 17, 2013 00:54
-
-
Save luis-almeida/7507544 to your computer and use it in GitHub Desktop.
Triggering an event in vanilla JavaScript
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
// http://stackoverflow.com/a/2490876 | |
var event; | |
if (document.createEvent) { | |
event = document.createEvent("HTMLEvents"); | |
event.initEvent("dataavailable", true, true); | |
} else { | |
event = document.createEventObject(); | |
event.eventType = "dataavailable"; | |
} | |
event.eventName = eventName; | |
event.memo = memo || { }; | |
if (document.createEvent) { | |
element.dispatchEvent(event); | |
} else { | |
element.fireEvent("on" + event.eventType, event); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment