Reputation: 42185
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
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
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