Skip to content

Instantly share code, notes, and snippets.

@samuelastech
Last active April 28, 2022 13:39
Show Gist options
  • Save samuelastech/b039e07280d7fe3462926e0238fc1855 to your computer and use it in GitHub Desktop.
Save samuelastech/b039e07280d7fe3462926e0238fc1855 to your computer and use it in GitHub Desktop.
Multiple JavaScript events added at once
/*
* 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