Created
October 28, 2011 17:01
-
-
Save timmywil/1322771 to your computer and use it in GitHub Desktop.
Fire an event cross-browser
This file contains hidden or 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 fire; | |
if ( document.createEvent ) { | |
fire = function( node, type ) { | |
var event = document.createEvent('HTMLEvents'); | |
event.initEvent( type, true, true ); | |
node.dispatchEvent( event ); | |
}; | |
} else { | |
fire = function( node, type ) { | |
var event = document.createEventObject(); | |
node.fireEvent( 'on' + type, event ); | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment