Created
September 22, 2012 14:39
-
-
Save lin04com/3766358 to your computer and use it in GitHub Desktop.
nextSibling (smart use of dom methods)
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 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