在jQuery中选择每个可见的最后一个孩子 [英] Select every visible last child in jQuery

查看:200
本文介绍了在jQuery中选择每个可见的最后一个孩子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获得每个 tr 中的最后一个可见 td

I would like to get the last visible td in each tr in a table.

这不起作用,因为它尝试选择最后一个子如果可见:

This does not work because it attempts to select the last child if it is visible:

var last_visible_cells = $(table).find("tr td:visible:last-child");

到目前为止,我想到的最简单的方法是使用。每个循环遍历 tr 元素,并将每个最后可见的 td 一个新的选择器列表。

So far the simplest method I've thought of is to use a .each to loop through the tr elements and append each of the last visible tds to a new selector list.

有更简单的方法吗?

var last_visible_cells = $(table).find("tr").lastMatching("td:visible");


推荐答案

您可以:

$('table tr').find('td:visible:last').addClass('last-visible');

查看完整示例(jQuery 1.2+ compatible)

See a full example (jQuery 1.2+ compatible)

这篇关于在jQuery中选择每个可见的最后一个孩子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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