views:

119

answers:

1

Hello, I'm trying to add a css class to the first td (cell) (and no other td) of each tr (row) in my table.

Can someone help me with the jQuery selector for this please?

Thank you!

+2  A: 

Use the first-child selector:

$("table tr td:first-child").text("I am the first child of the row");

A little test: http://jsfiddle.net/WxzfQ/

karim79
Ahhh I thought I need the > in there to specify descendants... let me try this :)
Alex
Works! Thank you buddy.
Alex
`table > tr` messes up with browsers that like to add `tbody` elements into your markup (firefox and chrome are two culprits).
karim79