Reputation: 2527
How do I target the second <tr>
in a table using jQuery? Do I use .closest
or 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>
Upvotes: 38
Views: 93568
Reputation: 61812
Use the :first
selector in combination with the insertAfter()
function:
$("TheElementToInsert").insertAfter(".myClass tr:first");
Upvotes: 7
Reputation: 22619
Use the nth-child selector. See http://api.jquery.com/nth-child-selector/
$('.myclass tr:nth-child(2)')
Upvotes: 49