Skip to content

Instantly share code, notes, and snippets.

@ktrysmt
Last active October 10, 2016 02:26
Show Gist options
  • Save ktrysmt/6dffea53a73e7e159033f01ac5e34918 to your computer and use it in GitHub Desktop.
Save ktrysmt/6dffea53a73e7e159033f01ac5e34918 to your computer and use it in GitHub Desktop.
Using setImmediate with DOM operations.
var child = document.getElementById("id").childNodes
var length=child.length,start=0;
var MAX_EXECUTION_COUNT=100;
setImmediate(function loop(){
for(var i=start;(i<start+MAX_EXECUTION_COUNT) && i<length ;i=(i+1)|0){
console.log(child[i])
}
if(i<length){
start += MAX_EXECUTION_COUNT;
setImmediate(loop,0);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment