views:

2512

answers:

3

This may sound like a simple question, but I just cannot seem to find an answer on google, probably because the search term will bring back quite a lot of irrelevance.

I would like a jQuery selector to select all odd table rows, that are not in <thead> and apply a css class to them all.

"table.cp-ss-grid tr:odd"

The above selector will bring back all odd rows in the table correctly, but will include the thead rows (on ie)

How would I in the selector do an and, i.e. something like:

"table.cp-ss-grid tr:odd:not(thead)"

the above doesn't work and still brings back the thead rows

Any ideas?

A: 

if you use th to head and td to other rows , you can check that the have child of td,

.children('td')
Haim Evgi
+4  A: 

Why not do:

$('table.cp-ss-grid > tbody > tr:odd');

To explicitly select the body rows? All browsers will add a tbody for you if you don't have one.

Paolo Bergantino
NB: Browsers will add tbody for HTML but not for XHTML. (XHTML served as text/html counts as HTML - one more reason why its a bad idea to do that)
David Dorward
A: 
"table.cp-ss-grid tr:odd" select all the odd rowb which will not include the header

if you want to specify a color of the header use ":nth-child(n)"

Rony