Skip to content

Instantly share code, notes, and snippets.

@timmywil
Created October 28, 2011 17:01
Show Gist options
  • Save timmywil/1322771 to your computer and use it in GitHub Desktop.
Save timmywil/1322771 to your computer and use it in GitHub Desktop.
Fire an event cross-browser
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