jquery How to select the 1st cell of each table row
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/
加载中,请稍侯......
精彩评论