Last active
November 1, 2018 04:11
-
-
Save olivx/3cac0eada7a4853306d74192aba4128c to your computer and use it in GitHub Desktop.
vanilla java script simulando cick
This file contains hidden or 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
| /** | |
| * Simulate a click event. | |
| * @public | |
| * @param {Element} elem the element to simulate a click on | |
| */ | |
| var simulateClick = function (elem) { | |
| // Create our event (with options) | |
| var evt = new MouseEvent('click', { | |
| bubbles: true, | |
| cancelable: true, | |
| view: window | |
| }); | |
| // If cancelled, don't dispatch our event | |
| var canceled = !elem.dispatchEvent(evt); | |
| }; | |
| var someLink = document.querySelector('a'); | |
| simulateClick(someLink); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment