嘿,我需要用給定的類名稱來計算嵌套的div。例如:在JavaScript中計數嵌套的div
<div id = "divA">
<div class = "anotherName"></div>
<div class = "toBeCounted"></div>
<div class = "someName"></div>
<div class = "toBeCounted"></div>
<div class = "toBeCounted"></div>
<div class = ""></div>
</div>
<div id = "divB">
<div class = ""></div>
<div class = "toBeCounted"></div>
<div class = ""></div>
<div class = "toBeCounted"></div>
</div>
所以,如果我想要數「toBeCounted」,我會得到3的divA和2的divB。
這假設OP沒有針對IE瀏覽器<8(並且希望他們不是) – 2015-02-05 16:01:55
@ElGuapo是的,這是真的 - 這是我的項目的一部分,讓IE8走出去,讓世界相信它可以' t可能是真實的 – Pointy 2015-02-05 16:04:26
HAHAHAHAHAHAHAHAHAHAHAHA – 2015-02-05 16:59:02