-
-
Save juanjosezg/02f5c32fd801d16ac8734c3a235051a9 to your computer and use it in GitHub Desktop.
Add the capability to attach multiple events to an element, just like jQuery does
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
/** | |
* multipleEventsListeners.js | |
* Add the capability to attach multiple events to an element, just like jQuery does | |
* https://gist.github.com/juanbrujo/a1f77db1e6f7cb17b42b | |
*/ | |
function multipleEventsListeners(elem, events, func) { | |
var event = events.split(' '); | |
for (var i = 0; i < event.length; i++) { | |
elem.addEventListener(event[i], func, false); | |
} | |
} | |
/* | |
Use: | |
var input = document.querySelector('input'); | |
multipleEventsListeners(input, 'keyup change', function(e){ | |
console.log(this.value); | |
}); | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment