Created
December 10, 2008 16:25
-
-
Save edspencer/34363 to your computer and use it in GitHub Desktop.
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
/** | |
* Recursively counts the number of DOM domNodes inside a given domNode | |
* @param {DomNode} domNome The DOM node to count children for (defaults to the body DOM node) | |
* @return {Number} The number of DOM nodes inside this domNode | |
*/ | |
countNodes = function(domNode) { | |
var domNode = domNode || document.body; | |
var runningTotal = 1; //this domNode | |
if (domNode.childNodes.length > 0) { | |
for (var i=0; i < domNode.childNodes.length; i++) { | |
runningTotal += countNodes(domNode.childNodes[i]); | |
}; | |
}; | |
return runningTotal; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment