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"?
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/
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/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With