I want to create a condition to check if there is iany row in the table or the row is the only one left.
So, I have:
<table>
<tr>
<td>AAAAAAA</td><td><a class="btn-row-delete">DELETE</a></td>
</tr>
<tr>
<td>BBBBBBB</td><td><a class="btn-row-delete">DELETE</a></td>
</tr>
<tr>
<td>CCCCCCC</td><td><a class="btn-row-delete">DELETE</a></td>
</tr>
</table>
<table>
<tr>
<td>BBBBBBB</td><td><a class="btn-row-delete">DELETE</a></td>
</tr>
</table>
$('form').on('click', '.btn-row-delete', function(e) {
e.preventDefault();
$(this).closest('tr').remove();
return false;
});
You could just check the length of the array which contains the <tr>
elements.
if($('table tr').length>1)
$(this).closest('tr').remove();