使用jQuery计算即时小孩div元素 [英] Count immediate child div elements using jQuery
本文介绍了使用jQuery计算即时小孩div元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下HTML节点结构:
< div id =foo>
< div id =bar>< / div>
< div id =baz>
< div id =biz>< / div>
< / div>
< span>< / span>
< / div>
如何计算 foo $ c的直接子代数$ c>,类型为
div
?在上面的例子中,结果应该是两个( bar
和 baz
)。
解决方案
$(#foo> div)长度
/ pre>
使用id'foo'的元素的直接子元素是div。然后检索生成的包裹集的大小。
I have the following HTML node structure:
<div id="foo"> <div id="bar"></div> <div id="baz"> <div id="biz"></div> </div> <span></span> </div>
How do I count the number of immediate children of
foo
, that are of typediv
? In the example above, the result should be two (bar
andbaz
).解决方案$("#foo > div").length
Direct children of the element with the id 'foo' which are divs. Then retrieving the size of the wrapped set produced.
这篇关于使用jQuery计算即时小孩div元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文