Skip to content

Instantly share code, notes, and snippets.

@avhm
Created September 21, 2011 16:14
Show Gist options
  • Save avhm/1232502 to your computer and use it in GitHub Desktop.
Save avhm/1232502 to your computer and use it in GitHub Desktop.
Simulate Mouse Click
function simulateMouseClick(selector) {
var targets = document.querySelectorAll(selector),
evt = document.createEvent('MouseEvents'),
i, len;
evt.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
for ( i = 0, len = targets.length; i < len; ++i ) {
targets[i].dispatchEvent(evt);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment