how about adding a class to your shared string
<tr class="grand-total"></tr>
then in jquery you do
$('#myTable tr.grand-total').before('<tr></tr>');
this way you are not doing this based on a position that can change, but instead is based on something meaningful like a βtotal amount"
source share