Created
June 22, 2025 12:59
-
-
Save jrc03c/e3588a7a348d14210d06c2aeff902930 to your computer and use it in GitHub Desktop.
Get the "depth" of an element in a web page
This file contains hidden or 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
function getElementDepth(el) { | |
return el.parentElement ? 1 + getElementDepth(el.parentElement) : 0 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment