开发者

How to select all the first <td> of <tr>?

Here's a part of the table,

<tbody id="list_tbody">
   <tr class="infoRow">
      <td></td>
      <td></td>
      <td></td>
   </tr>
   <tr class="infoRow">
      <td></td>
      <td></td>
      <td></td>
   </tr>
   <tr class="infoRow">
      <td></td>
      <td></td>
      <td></td>
   </tr>
</tbody>

the tag continues... and this is my jQuery code:

$("tr.infoRow td:eq(0)").css("border-left", "1px solid #d0d0d0");

How to select all the first <td> that is inside all the <tr>? On my current code, it only selects the first <td&开发者_如何学Gogt; of the first <tr>. Please correct my jQuery code.


$("tr.infoRow td:first-child").css("border-left", "1px solid #d0d0d0");


Try this

$("tr.infoRow td::nth-child(1)").css("border-left", "1px solid #d0d0d0");

Note: nth-child is 1 indexed so you can pass some other number if you want to select any other column.


You can use nth-child selector too:

$("tr.infoRow td:nth-child(1)").css("border-left", "1px solid #d0d0d0");


alert($('table tr td:nth-child(n)').size()). It should show you '3'. 

I think you need to change 'n' for 0 or 1. I don't remember. Check jQuery docs for nth-chi

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜