Skip to content

Instantly share code, notes, and snippets.

@petermikitsh
Created December 13, 2016 23:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save petermikitsh/5fcbacd27fc65a9bb5099ee673d7a331 to your computer and use it in GitHub Desktop.
Save petermikitsh/5fcbacd27fc65a9bb5099ee673d7a331 to your computer and use it in GitHub Desktop.
Utility functions for inspecting various DOM characteristics
// Find the height of the deepest DOM node
function getHeight(node) {
var children = node.children;
if (children.length === 0) {
return 1;
} else {
var childHeights = Array.from(children).map(function (child) {
return getHeight(child);
});
return 1 + Math.max.apply(null, childHeights);
}
}
console.log(getHeight(document.documentElement));
// Count all DOM Nodes on page
function getNodesInPage() {
return document.getElementsByTagName('*').length;
}
console.log(getNodesInPage());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment