DaveDev
DaveDev

Reputation: 42185

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

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?

Upvotes: 4

Views: 117

Answers (3)

Drekembe
Drekembe

Reputation: 2716

Try

$("results-table tr:not(.hidden-row)").filter(":even")

Upvotes: 1

Fr&#233;d&#233;ric Hamidi
Fr&#233;d&#233;ric Hamidi

Reputation: 262979

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.

Upvotes: 7

Dogbert
Dogbert

Reputation: 222198

You can use filter.

$(".results-table tr:even").filter(function() { return ! $(this).hasClass('hidden-row'); })
    .children("td")
    .css("background-color", "#f1f5f9");

Upvotes: 4

Related Questions