jQuery - 选择表中的第二行?

时间:2011-11-13 23:44:15

标签: jquery jquery-selectors

如何使用jQuery定位表中的第二个<tr>?我使用.closest还是nth-child

// something like this..
var MyLocation = $('.myclass').closest('tr').after('tr');   // fixed


<table class ='myclass'>
<tr>
  <td></td>
</tr>
   <!-- put some thing here -->
<tr>

</tr>

3 个答案:

答案 0 :(得分:56)

$('.myclass tr').eq(1)

这将抓住第二个。

答案 1 :(得分:34)

使用nth-child选择器。见http://api.jquery.com/nth-child-selector/

$('.myclass tr:nth-child(2)')

答案 2 :(得分:6)

:first选择器与insertAfter()功能结合使用:

$("TheElementToInsert").insertAfter(".myClass tr:first");
相关问题