Skip to content

Instantly share code, notes, and snippets.

@scizers
Last active August 29, 2015 14:06
Show Gist options
  • Save scizers/54cf210e8b47e83ea10e to your computer and use it in GitHub Desktop.
Save scizers/54cf210e8b47e83ea10e to your computer and use it in GitHub Desktop.
Simulate Click in jQuery
jQuery(document).ready(function(){
setTimeout(function(){
jQuery.fn.simulateClick = function() {
return this.each(function() {
if('createEvent' in document) {
var doc = this.ownerDocument,
evt = doc.createEvent('MouseEvents');
evt.initMouseEvent('click', true, true, doc.defaultView, 1, 0, 0, 0, 0, false, false, false, false, 0, null);
this.dispatchEvent(evt);
} else {
this.click(); // IE Boss!
}
});
}
jQuery('#prateek').simulateClick('click');
},2000)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment