Skip to content

Instantly share code, notes, and snippets.

@lxcodes
Created June 6, 2011 14:26
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 lxcodes/1010361 to your computer and use it in GitHub Desktop.
Save lxcodes/1010361 to your computer and use it in GitHub Desktop.
JavaScript TriggerEvent
Element.prototype.triggerEvent = function(eventName)
{
if (document.createEvent)
{
var evt = document.createEvent('HTMLEvents');
evt.initEvent(eventName, true, true);
return this.dispatchEvent(evt);
}
if (this.fireEvent)
return this.fireEvent('on' + eventName);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment