jquery - 为什么是:last-child not giving me the results I expect?

标签 jquery html jquery-selectors

jsFiddle在这里:http://jsfiddle.net/_mtr/uqMZJ/

基本上,当文档准备好时,只有 10 行左右的表格不会被隐藏。我想要最后一个非隐藏行的索引,但我的 jQuery 选择器让我失望。

最佳答案

您滥用了 :last-child选择器,匹配其父元素的最后一个子元素。您实际上想要匹配集中的最后一个元素,因此您应该使用 :last选择器:

i2 = $('table .visible:last').index();

您会发现更新的 fiddle here .

关于jquery - 为什么是:last-child not giving me the results I expect?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9280023/

相关文章:

html - 在移动设备上禁用滚动

jquery - 如何在文档加载时使用 jquery 在选择框中选择特定项目

javascript - jQuery .not(), 多个带有 id 的排除

jquery - CKEditor自定义图像浏览器

html - 将响应按钮放在 TextArea 中

javascript - 如何从 JavaScript 调用 php/wordpress 命令?

CSS:全尺寸 div 显示浏览器滚动条

javascript - 基本的 jQuery 选择器问题

javascript - 添加嵌套引号

javascript - 显示textarea的多行纯文本?