考慮我有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 –