Created
August 27, 2014 13:23
-
-
Save bendc/22d3c68bdc62c2dfe429 to your computer and use it in GitHub Desktop.
each() for NodeLists
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
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