Skip to content

Instantly share code, notes, and snippets.

@hyhoocchan
Created November 10, 2015 03:27
Show Gist options
  • Select an option

  • Save hyhoocchan/6c9fec9e383cc2790e0a to your computer and use it in GitHub Desktop.

Select an option

Save hyhoocchan/6c9fec9e383cc2790e0a to your computer and use it in GitHub Desktop.
Trigger Event Prototype by jQuery
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);
};
jQuery('element id').triggerEvent('click');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment