Skip to content

Instantly share code, notes, and snippets.

@jesse1981
Last active December 16, 2015 10:09
Show Gist options
  • Save jesse1981/5418388 to your computer and use it in GitHub Desktop.
Save jesse1981/5418388 to your computer and use it in GitHub Desktop.
Script a click event to object.
function fakeClick(event, anchorObj) {
if ((typeof(anchorObj)!="undefined") && (typeof(anchorObj.click)!="undefined")) {
anchorObj.click()
}
else if(document.createEvent) {
if(event.target !== anchorObj) {
var evt = document.createEvent("MouseEvents");
evt.initMouseEvent("click", true, true, window,
0, 0, 0, 0, 0, false, false, false, false, 0, null);
var allowDefault = anchorObj.dispatchEvent(evt);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment