Created
June 10, 2015 15:37
-
-
Save IonDen/6fd9bfbdb6869af4bffd to your computer and use it in GitHub Desktop.
Crossbrowser event trigger in pure 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
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