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.
'<tr><td>4<span onclick="del()">del row</span></td></tr>'stop downvote!thiswhen using inline script is the window. 2. you need to replaceparentwithclosest. 3. better usedelegate eventsee my updated answer below.