使用 jQuery 计算直接子 div 元素 [英] Count immediate child div elements using jQuery

查看:26
本文介绍了使用 jQuery 计算直接子 div 元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下 HTML 节点结构:

<div id="bar"></div><div id="baz"><div id="biz"></div>

<span></span>

如何计算 foo 类型的 div 的直接子代的数量?在上面的例子中,结果应该是两个(barbaz).

解决方案

$("#foo > div").length

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 type div? In the example above, the result should be two (bar and baz).

解决方案

$("#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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆