Skip to content

Instantly share code, notes, and snippets.

@luis-almeida
Created November 17, 2013 00:54
Show Gist options
  • Save luis-almeida/7507544 to your computer and use it in GitHub Desktop.
Save luis-almeida/7507544 to your computer and use it in GitHub Desktop.
Triggering an event in vanilla JavaScript
// 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