This is my js code:
<script>
function add(){
$('#myTable tr:last').after('<tr><td>4<span onclick="del()">del row</span></td></tr>');
}
function del(){
$(this).parent('tr').remove();
}
</script>
and html:
<table id="myTable" border="1">
<tr><td>1</td></tr>
<tr><td>2</td></tr>
<tr><td>3</td></tr>
</table>
<span onclick="add()">add row</span>
My add button work nice but my del button not work. When del row clicked nothing happened.
Little change with your code
Working sample
Another easier approach, not need radical change in your code
I think more easy will be that, if you add a class to the
del row spanand removeonclicklike following:and set delegate event handler like following:
and write your
del()function like following:Working Sample
And one important note
Don’t forget to place your whole code within
in short