Skip to content

Instantly share code, notes, and snippets.

@IonDen
Created June 10, 2015 15:37
Show Gist options
  • Save IonDen/6fd9bfbdb6869af4bffd to your computer and use it in GitHub Desktop.
Save IonDen/6fd9bfbdb6869af4bffd to your computer and use it in GitHub Desktop.
Crossbrowser event trigger in pure JavaScript
var trigger = function (el, type) {
var event;
if (document.createEvent) {
event=document.createEvent('HTMLEvents');
event.initEvent(type,true,true);
} else {
event=document.createEventObject();
event.eventType=type;
}
event.eventName=type;
if (document.createEvent) {
el.dispatchEvent(event);
} else {
el.fireEvent('on'+event.eventType,event);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment