Skip to content

Instantly share code, notes, and snippets.

@ThinkDigitalSoftware
Last active April 14, 2018 20:35
Show Gist options
  • Save ThinkDigitalSoftware/3fa2107e6ed9913ad5260b79bd9c5ed7 to your computer and use it in GitHub Desktop.
Save ThinkDigitalSoftware/3fa2107e6ed9913ad5260b79bd9c5ed7 to your computer and use it in GitHub Desktop.
Simulate a click on a Javascript Element. Credit goes to KooiInc, https://stackoverflow.com/a/2706236/2880055
function eventFire(el, etype){
//Usage: eventFire(document.getElementById('mytest1'), 'click');
if (el.fireEvent) {
el.fireEvent('on' + etype);
} else {
var evObj = document.createEvent('Events');
evObj.initEvent(etype, true, false);
el.dispatchEvent(evObj);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment