Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@julesbou
Created May 8, 2016 10:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save julesbou/82b0f7043f56c72f6a32d518ad88b354 to your computer and use it in GitHub Desktop.
Save julesbou/82b0f7043f56c72f6a32d518ad88b354 to your computer and use it in GitHub Desktop.
Node.prototype.on = HTMLElement.prototype.addEventListener
NodeList.prototype.on = function(event, cb) {
Array.prototype.forEach.call(this, el => el.addEventListener(event, cb))
}
// usage: $('.element').on('click', ...)
// usage: $('.list-of-elements').on('click', ...)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment