Wednesday, 21 August 2013

How to traverse the DOM to determine maximum nesting depth?

How to traverse the DOM to determine maximum nesting depth?

For example:
// ...
<body>
<div>
<div>
</div>
</div>
</body>
// ...
This nest depth would be 3? But more generally, how can I traverse the DOM
to find this information?
I'm interested in treating the DOM like an n-ary tree modeled as an object
literal as described in this post:
n-ary tree in JavaScript

No comments:

Post a Comment