Skip to content

Instantly share code, notes, and snippets.

@jjmu15
Created January 31, 2014 09:30
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 jjmu15/8728981 to your computer and use it in GitHub Desktop.
Save jjmu15/8728981 to your computer and use it in GitHub Desktop.
foreach element - vanilla js
function forEachElement(selector, fn) {
var elements = document.querySelectorAll(selector)
for (var i = 0; i < elements.length; i++)
fn(elements[i], i)
}
forEachElement(selector, function(el, i){
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment