To answer your first question:
$("#id tr").click(function() {
alert($("#id tr").index(this));
});
If you just do:
$("table tr").index(this);
and you have multiple tables on the page, you will get an erroneous result.
That being said, you don't need to know the index to move rows up and down in a table. For example:
<table id="foo">
<tr>
<td><a href="#" class="up">Up</a> <a href="#" class="down">down</a></td>
<td>First row</td>
</tr>
<tr>
<td><a href="#" class="up">Up</a> <a href="#" class="down">down</a></td>
<td>Second row</td>
</tr>
<tr>
<td><a href="#" class="up">Up</a> <a href="#" class="down">down</a></td>
<td>Third row</td>
</tr>
</table>
with something like:
$("a.up").click(function() {
var row = $(this).closest("tr");
if (row.prev().length > 0) {
row.insertBefore(row.prev());
}
return false;
});
$("a.down").click(function() {
var row = $(this).closest("tr");
if (row.next().length > 0) {
row.insertAfter(row.next());
}
return false;
});