I would like the following script to move a table row to the top of a table. I can't figure out how to reference the id of the first row, however, since the ID is set dynamically, I tried row.insertAfter(row.first());
but it's making the row disappear instead of moving it. Any ideas how to reference the top row?
$(".top").click(function(){
var row = $(this).parents("tr:first");
if ($(this).is(".top")) {
row.inserAfter(row.first());
} else {
return false;
}
});
<tbody id="sortable">
<tr id="row1">
<td><a href="" class="top">Top</a></td>
</tr>
<tr id="row2">
<td><a href="" class="top">Top</a></td>
</tr>
<tr id="row3">
<td><a href="" class="top">Top</a></td>
</tr>
</tbody>