javascript - 使用 jQueryeach 函数来计算具有相同类的 div

标签 javascript jquery html css magento

我创建了一个8个div的css类,我需要使用jquery的each函数来计算div的数量并将结果显示在页面的html中,例如:“8个div出现”。

我创建了一个代码,但它不起作用,它不显示结果。

代码:

 <script>
    $( ".class" ).each(function( index ) {
      console.log( index + ": " + $( this ).text() );
    });
    </script>

最佳答案

如果你只是想计算它们,你可以这样做: $('.class').length

关于javascript - 使用 jQueryeach 函数来计算具有相同类的 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60176591/

相关文章:

jquery - 将类添加到正文时销毁 jQuery 脚本

html - Favicon 在 Internet Explorer 中不工作,如何解决?

javascript - 无法使用箭头键在文本框之间移动

javascript - 深入了解如何将两个表单字段提交到 2 页之外的单独页面

javascript - 变换旋转和翻转效果——CSS3和jQuery

jquery - KendoUI 可观察对象 : Set multiple attributes

javascript - 为什么我的素数程序不起作用?

javascript - 数组中的对象

html - Swift - 返回两个 NSRanges 之间的字符串

javascript - Google Apps 脚本文本区域