Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I select all rows that are even, but not hidden?

Tags:

jquery

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?

like image 960
DaveDev Avatar asked Dec 17 '22 10:12

DaveDev


1 Answers

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.

like image 157
Frédéric Hamidi Avatar answered Jan 10 '23 06:01

Frédéric Hamidi