计算<div>的数量 [英] Count the number of <div>

查看:24
本文介绍了计算<div>的数量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用 jQuery 来计算 div 元素的数量?

我有这个代码:

<div class="name">text text</div><div class="name">text text text ... </div><div class="name">text ...</div>

并得到数字:3

解决方案

$("#center div").length 会给你计数.

Is it possible using jQuery to count the number of div elements?

I have this code:

<div id = "center">
  <div class ="name">text text</div>
  <div class ="name">text text text ... </div>
  <div class ="name">text ...</div>
</div>

And get number: 3

解决方案

$("#center div").length will give you the count.

这篇关于计算&lt;div&gt;的数量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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