Created
December 11, 2017 13:45
-
-
Save jdelafon/64a9eeea5b4d68be2e55557821cc77ab to your computer and use it in GitHub Desktop.
Simulate a click on a DOM element in Javascript
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
function fireEventClick(elem){ | |
if(document.createEvent){ | |
var e = document.createEvent('MouseEvents'); | |
e.initMouseEvent('click', /* Event type */ | |
true, /* Can bubble */ | |
true, /* Cancelable */ | |
document.defaultView, /* View */ | |
1, /* Mouse clicks */ | |
0, /* Screen x */ | |
0, /* Screen y */ | |
0, /* Client x */ | |
0, /* Client y */ | |
false, /* Ctrl */ | |
false, /* Alt */ | |
false, /* Shift */ | |
false, /* Meta */ | |
0, /* Button */ | |
null); /* Related target */ | |
elem.dispatchEvent(e); | |
} else { // pour IE | |
elem.click(); | |
} | |
} | |
// Ref: https://blog.kodono.info/wordpress/2009/09/04/simuler-un-click-sur-un-bouton-ou-un-lien-programmation/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment