Skip to content

Instantly share code, notes, and snippets.

@lin04com
Created September 22, 2012 14:39
Show Gist options
  • Save lin04com/3766358 to your computer and use it in GitHub Desktop.
Save lin04com/3766358 to your computer and use it in GitHub Desktop.
nextSibling (smart use of dom methods)
function LoopChildren(elm) {
var nodes = elm.childNodes;
var length = nodes.length;
for (var i = 0; i < length; i++) {
var node = nodes[i];
//...
}
}
//better use...
function LoopChildren2(elm) {
var nodes = elm.firstChild;
while (node != null) {
//...
node = node.nextSibling;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment