Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery Selector Problem (First TD in each TR in a table)

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!

like image 830
Alex Avatar asked Jun 01 '10 18:06

Alex


People also ask

How do you select the first element with the selector statement?

The :first selector selects the first element. Note: This selector can only select one single element. Use the :first-child selector to select more than one element (one for each parent). This is mostly used together with another selector to select the first element in a group (like in the example above).

How do I get the first row of a table in jquery?

The following code shows how to select the first row in a table $("tr:first").


1 Answers

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/

like image 142
karim79 Avatar answered Oct 14 '22 06:10

karim79