我如何选择所有均匀但不隐藏的行?(How can I select all rows that are even, but not hidden?)

我想要交替行的背景颜色。

我试图选择没有隐藏的偶数行的<td>元素。

我在尝试以下内容:

$(".results-table tr:not(.hidden-row):even") .children("td") .css("background-color", "#f1f5f9");

但它不起作用。 我想我不能像我那样使用2个选择器。 有人可以建议如何正确地做到这一点?

I want to alternate the background-color of rows.

I'm trying to select <td> elements of even rows that are not hidden.

I'm trying the following:

$(".results-table tr:not(.hidden-row):even") .children("td") .css("background-color", "#f1f5f9");

but it's not working. I guess I can't use 2 selectors the way I am. Can someone suggest how to do this correctly?

最满意答案

你可以使用filter()来达到这个目的:

$(".results-table tr:not(.hidden-row)").filter(":even") .children("td").css("background-color", "#f1f5f9");

这也会提高性能,因为:即使是jQuery扩展,也不是原生的CSS选择器。

You can use filter() for that purpose:

$(".results-table tr:not(.hidden-row)").filter(":even") .children("td").css("background-color", "#f1f5f9");

This will also increase performance, since :even is a jQuery extension, not a native CSS selector.

我如何选择所有均匀但不隐藏的行?(How can I select all rows that are even, but not hidden?)

我想要交替行的背景颜色。

我试图选择没有隐藏的偶数行的<td>元素。

我在尝试以下内容:

$(".results-table tr:not(.hidden-row):even") .children("td") .css("background-color", "#f1f5f9");

但它不起作用。 我想我不能像我那样使用2个选择器。 有人可以建议如何正确地做到这一点?

I want to alternate the background-color of rows.

I'm trying to select <td> elements of even rows that are not hidden.

I'm trying the following:

$(".results-table tr:not(.hidden-row):even") .children("td") .css("background-color", "#f1f5f9");

but it's not working. I guess I can't use 2 selectors the way I am. Can someone suggest how to do this correctly?

最满意答案

你可以使用filter()来达到这个目的:

$(".results-table tr:not(.hidden-row)").filter(":even") .children("td").css("background-color", "#f1f5f9");

这也会提高性能,因为:即使是jQuery扩展,也不是原生的CSS选择器。

You can use filter() for that purpose:

$(".results-table tr:not(.hidden-row)").filter(":even") .children("td").css("background-color", "#f1f5f9");

This will also increase performance, since :even is a jQuery extension, not a native CSS selector.