I have an HTML table in which rows can be added dynamically by button click(Also done with jQuery). What I want now is,I need to have a button by the side of each row. Pressing it would delete that particular row.
The table is as follows.
<tr class="item-row">
<td class="item-name">
<div class="delete-wpr"><textarea></textarea><a class="delete" href="javascript:;" title="Remove row">X</a></div></td>
<td><input type="text" class="slno"/></td>
<td><input type="text" class="cost"/></td>
<td><input type="text" class="qty"/></td>
<td><span class="price"></span></td>
</tr>
The Jquery to add more rows is as follows.
$("#addrow").click(function(){
$(".item-row:last").after('<tr class="item-row"><td class="item-name"><div class="delete-wpr"><input type="text" class="slno"/><a class="delete" href="javascript:;" title="Remove row">X</a></div></td><td><input type="text" class="slno"/></td><td><input type="text" class="cost"/></td><td><input type="text" class="qty"/></td><td><span class="price"></span></td></tr> ');
The function I am using is this. But it's not working.
$(".delete").on('click',function(){
$(this).parents('.item-row').remove();
update_total();
if ($(".delete").length < 2) $(".delete").hide();
});
So how do I do this?