Skip to content

Instantly share code, notes, and snippets.

@bendc
Created August 27, 2014 13:23
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bendc/22d3c68bdc62c2dfe429 to your computer and use it in GitHub Desktop.
Save bendc/22d3c68bdc62c2dfe429 to your computer and use it in GitHub Desktop.
each() for NodeLists
function each(nodelist, callback) {
var i = -1,
l = nodelist.length
while (++i < l)
callback.call(nodelist.item(i), i)
}
// Usage:
var divs = document.querySelectorAll("div")
each(divs, function(index) {
this.textContent = "div index: " + index
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment