Last active
August 29, 2015 14:06
-
-
Save scizers/54cf210e8b47e83ea10e to your computer and use it in GitHub Desktop.
Simulate Click in jQuery
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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