Guest User

Untitled

a guest
Mar 19th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.43 KB | None | 0 0
  1. function getDomDepthLevel(root = document.documentElement) {
  2. let pathInfo = {
  3. route: [],
  4. level: 0
  5. };
  6. for (let i = 0, j = root.children.length; i < j; i++) {
  7. const curNodePathInfo = getDomDepthLevel(root.children[i]);
  8. if (curNodePathInfo.level > pathInfo.level) {
  9. pathInfo = curNodePathInfo;
  10. }
  11. }
  12. pathInfo.route.unshift(root);
  13. pathInfo.level += 1;
  14. return pathInfo;
  15. }
Add Comment
Please, Sign In to add comment