Reputation: 5870
I have a table like this:
<table id="myTable">
<tr><td>1sta</td><td>2nd</td></tr>
<tr><td>1stb</td><td>2nd</td></tr>
<tr><td>1stc</td><td>2nd</td></tr>
<tr><td>1std</td><td>2nd</td></tr>
</table>
Using jQuery
How do I select the 1st <td>
element in each row of "myTable"?
Upvotes: 6
Views: 1493
Reputation: 21
Use this selector '#myTable td:first-child'
.
That will select the first td
for every tr
. Avoid the temptation to use :first
instead of :first-child
. :first
will only select a single element. In this case it would be the first cell of the first row.
http://api.jquery.com/first-child-selector/
Upvotes: 2
Reputation: 322492
The first-child
selector grabs each td
that is the first child of its parent (the tr
in this case).
$('#myTable td:first-child');
http://api.jquery.com/first-child-selector/
Upvotes: 8