What\'s the easiest way to get the depth of an element in pure JavaScript or jQuery? By \"depth\" I mean how many elements deep is it nested, or how many ancestors does it h
function elementDepth(el){ var depth = 0 while(null!==el.parentElement){ el = el.parentElement depth++ } return depth } console.log(elementDepth(document.getElementById('test')))
Hi
It says 3 in this example because it counts the outer , the and the tag. 0 讨论(0) 查看其它6个回答 发布评论: 提交评论 加载中... 验证码 看不清? 提交回复
, the and the tag. 0 讨论(0) 查看其它6个回答 发布评论: 提交评论 加载中... 验证码 看不清? 提交回复