$(document).ready(function(){
$('#addrow').click(function(){
$('.item-row:last').after('<tr class="item-row"><td class="item-name"><div class="delete-wpr"><textarea>Item Name</textarea><a class="delete" href="javascript:;" title="Remove row">X</a></div></td><td><textarea class="cost">0</textarea></td><td><textarea class="qty">0</textarea></td><td><textarea class="vat 5%">0</textarea></td><td><span class="price">0</span></td> </tr>')
bind();
})
bind() ;
function bind(){
$('.cost').blur(update_price);
$('.qty').blur(update_price);
}
function update_price(){
var row = $(this).parents('.item-row');
var cost = row.find('.cost').val();
var qty = row.find('.qty').val();
row.find('.price').html(Number(qty) * Number(cost) );
update_total()
}
function update_total(){
var total = 0 ;
$('.price').each(function(i){
price = $(this).html();
if(price > 0){
total += Number(price);
}
})
var tax = total * 0.05;
$('#subtotal').html(total);
$('#tax').html(tax);
$('#total').html(total+tax);
}
$('.delete').live('click',function(){
$(this).parents('.item-row').remove();
update_total() ;
})
})
* { margin: 0; padding: 0; }
body { font: 14px/1.4 Georgia, serif; }
#page-wrap { width: 800px; margin: 0 auto; }
textarea { border: 0; font: 14px Georgia, Serif; overflow: hidden; resize: none; }
table { border-collapse: collapse; }
table td, table th { border: 1px solid black; padding: 5px; }
#header { height: 15px; width: 100%; margin: 20px 0; background: #222; text-align: center; color: white; font: bold 15px Helvetica, Sans-Serif; text-decoration: uppercase; letter-spacing: 20px; padding: 8px 0px; }
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<!DOCTYPE html>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=UTF-8' />
<title>Invoice</title>
<link rel='stylesheet' type='text/css' href='css/style.css' />
<script type='text/javascript' src='js/jquery-1.3.2.min.js'></script>
<script type='text/javascript' src='js/custom.js'></script>
</head>
<body>
<div id="page-wrap">
<textarea id="header">INVOICE</textarea>
<div id="identity">
<textarea id="address">
text
text
</textarea>
</div></answer1>
<exanswer1><div class="answer accepted" i="55215787" l="4.0" c="1552880226" a="ViYjMjM3OyYjMjQxO+G7i3QgVuG7i8WCxYLEgw==" ai="7031906">
<p>Probably, I think you wanted to calculate the tax value and add it to the total.</p>
<p>I think this would work.</p>
<p><div>
<div>
<pre class="lang-js"><code>$(document).ready(function(){
$('#addrow').click(function(){
$('.item-row:last').after('<tr class="item-row"><td class="item-name"><div class="delete-wpr"><textarea>Item Name</textarea><a class="delete" href="javascript:;" title="Remove row">X</a></div></td><td><textarea class="cost">0</textarea></td><td><textarea class="qty">0</textarea></td><td><textarea class="vat 5%">0</textarea></td><td><span class="price">0</span></td> </tr>')
bind();
})
bind() ;
function bind(){
$('.cost').blur(update_price);
$('.qty').blur(update_price);
}
function update_price(){
var row = $(this).parents('.item-row');
var cost = row.find('.cost').val();
var qty = row.find('.qty').val();
row.find('.price').html(Number(qty) * Number(cost) );
update_total()
}
function update_total(){
var total = 0 ;
$('.price').each(function(i){
price = $(this).html();
if(price > 0){
total += Number(price);
}
})
var tax = total * 0.05;
$('#subtotal').html(total);
$('#tax').html(tax);
$('#total').html(total+tax);
}
$('.delete').live('click',function(){
$(this).parents('.item-row').remove();
update_total() ;
})
})
* { margin: 0; padding: 0; }
body { font: 14px/1.4 Georgia, serif; }
#page-wrap { width: 800px; margin: 0 auto; }
textarea { border: 0; font: 14px Georgia, Serif; overflow: hidden; resize: none; }
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<!DOCTYPE html>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=UTF-8' />
<title>Invoice</title>
<link rel='stylesheet' type='text/css' href='css/style.css' />
<script type='text/javascript' src='js/jquery-1.3.2.min.js'></script>
<script type='text/javascript' src='js/custom.js'></script>