考虑我有HTML如何在jQuery中获取当前元素深度?
<div id=test>
<a>test1</a>
<div>
<a>test2</a>
<a>test3</a>
</div>
</div>
第2 &第三环节都在不同的深度比第一个,如果我使用jQuery选择它们,如何识别深度它们的区别?
$('a').each(function() {
console.log($(this).text() + " and my current depth is: ");
});
http://stackoverflow.com/questions/4710943/js-jquery-get-depth-of-element,http://stackoverflow.com/questions/15509707/how-to-find-how-deep-an -element-is-nested-in-jquery –
你的问题已经关闭,所以我把我的答案放在这里:http://stackoverflow.com/a/24058845/747579 –