I have a main div in my page with a specific id. Now some input elements of the same class are present in this div. So how can I count the number of these elements of same class in this div using jQuery?

推荐答案

With jQuery you can use

$('#main-div .specific-class').length

otherwise in VanillaJS (from IE8 included) you may use

document.querySelectorAll('#main-div .specific-class').length;

Jquery相关问答推荐

多个 AJAX 调用;获取所有失败的呼叫

jQuery:在mousemove事件期间检测按下的鼠标按钮

将日期时间从 javascript 传递给 c# (Controller)

Ajax 替换而不是追加

当输入值以编程方式更改时触发更改事件?

在 Bootstrap 3 中向工具提示添加换行符

如何滚动到AngularJS中的页面顶部?

使用 jQuery 为 box-shadow 设置动画的正确方法

如何使用 jQuery 将表格的一行滚动到视图 (element.scrollintoView) 中?

在 select2 中使用 AJAX 进行标记

SCRIPT7002:XMLHttpRequest:网络错误 0x2ef3,由于错误 00002ef3 无法完成操作

在 jquery 中启用/禁用下拉框

使用 jQuery 从 AJAX 响应(json)构建表行

Rails 5:如何将 $(document).ready() 与 turbo-links 一起使用

jQuery表格行中的每个循环

如何使用 javascript 擦除所有内联样式并仅保留 css 样式表中指定的样式?

查找 id 以开头的 html 元素

调整浏览器大小时如何自动居中 jQuery UI 对话框?

Uncaught TypeError: undefined is not a function on loading jquery-min.js

如何淡出显示:inline-block