One method is to use jQuery's prepend()
to move the desired <tr>
(row) to the top of the table.
Note that:
If a single element selected this way is inserted into a single location elsewhere in the DOM, it will be moved into the target (not cloned).
If there is more than one target element, however, cloned copies of the inserted element will be created for each target except for the last one.
In my example, I use closest()
to traverse from the clicked <td>
to its containing <tr>
so that the entire row can be moved.
jQuery('#pp').on('click', function() {
jQuery(this).closest('tr').prependTo('table');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table>
<tr><td>...</td></tr>
<tr><td>...</td></tr>
<tr><td id="pp"><a><i class="">click to move this row to the top</i></a></td></tr>
<tr><td>...</td></tr>
</table>