Created
December 13, 2016 23:16
-
-
Save petermikitsh/5fcbacd27fc65a9bb5099ee673d7a331 to your computer and use it in GitHub Desktop.
Utility functions for inspecting various DOM characteristics
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
// 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