Skip to content

Instantly share code, notes, and snippets.

@tylerbuchea
Created May 27, 2013 18:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tylerbuchea/5658466 to your computer and use it in GitHub Desktop.
Save tylerbuchea/5658466 to your computer and use it in GitHub Desktop.
Simulate JavaScript events
function simulateEvent(element, type) {
// Check for createEventObject
if(document.createEventObject){
// Trigger for Internet Explorer
trigger = document.createEventObject();
element.fireEvent('on' + type, trigger);
}
else {
// Trigger for the good browsers
trigger = document.createEvent('HTMLEvents');
trigger.initEvent(type, true, true);
element.dispatchEvent(trigger);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment