If you are removing (delete ) the row then you should write the following code for the delete button id which we are appending.
<pre><td width="100px"><button class="remCF" id="' + newid + '" >Remove</button></td>\n\ </tr>');
Then you should add the following code to get the id of the delete button which is clicked and subtract that id's total_price from the subtotal.
$("#table1").on('click', '.remCF', function () {
var classname = '.totalprices' + $(this)[0].id;
var num = $(classname)[0].innerHTML
sum = sum - Number(num);
$('#subtotal').val(sum);
$(this).parent().parent().remove();
$('#table1 tbody tr').each(function (id) {
$($(this).find('td')[0]).html(id++);
});
});