Created
June 14, 2013 09:15
-
-
Save pixyj/5780563 to your computer and use it in GitHub Desktop.
Calculate total number of nodes in your web page.
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
var countNodes = function() { | |
var total = 1; | |
var count = function(node) { | |
var i, l; | |
l = node.children.length; | |
total += l; | |
for(i=0; i<l; i++) { | |
count(node.children[i]) | |
} | |
} | |
count(document.body); | |
return total; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment