Created
November 15, 2020 13:32
-
-
Save AitorAlejandro/2f55fe27d1a91bcc1b8f1ad2ee673093 to your computer and use it in GitHub Desktop.
How to trigger a specific event on a given element, optionally passing custom data
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
| const triggerEvent = (el, eventType, detail) => | |
| el.dispatchEvent(new CustomEvent(eventType, { detail })); | |
| // Examples | |
| triggerEvent(document.getElementById('myId'), 'click'); | |
| triggerEvent(document.getElementById('myId'), 'click', { username: 'bob' }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment