Last active
April 28, 2022 13:39
-
-
Save samuelastech/b039e07280d7fe3462926e0238fc1855 to your computer and use it in GitHub Desktop.
Multiple JavaScript events added at once
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
/* | |
* Add multiples "Event Listener" to an element | |
* @param {Node} element HTML Element | |
* @param {String} events All the events you want separated by a space | |
* @param {Object} fn The function you wanna execute to all these events | |
*/ | |
addEventListenerAll(element, events, fn){ // Function | |
events.split(' ').forEach(event => { | |
element.addEventListener(event, fn) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment