Skip to content

Instantly share code, notes, and snippets.

@dblodorn
Created March 22, 2017 20:58
Show Gist options
  • Select an option

  • Save dblodorn/66ca9226539c2c4ff52c15c5075bfbf1 to your computer and use it in GitHub Desktop.

Select an option

Save dblodorn/66ca9226539c2c4ff52c15c5075bfbf1 to your computer and use it in GitHub Desktop.
Element Iterate Shell Function
export const elementIterate = (selector,fn) => {
const itemToIterate = document.querySelectorAll(selector)
let i = 0
setTimeout(() => {
if(itemToIterate) {
while(i < itemToIterate.length) {
fn(itemToIterate,i)
i++
}
}
}, 5)
}
import {elementIterate} from './element-iterate'
const functionToRepeat = (itemToIterate,i) => {
console.log(itemToIterate[i] + [i])
}
elementIterate('.some-selector', functionToRepeat)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment