I have this piece of code
// TR Fading when deleted
$('.delete').live('click', function() {
$.ajax({
type: 'POST',
url: 'history/delete/id/'+$(this).attr('id')
});
$(this).closest('tr').fadeOut('slow', function() {
$(this).remove();
if($(this).closest('table').find('tbody').is(':empty'))
$('#latest').remove();
});
return false;
});
It triggers when I want to delete a table row through the delete button (as shows the image)
It may happen that the table becomes empty of table rows. I want to delete the whole table when this occurs, but the table isn't being removed. The line code $(this).remove();
works and this
seems to refer to the tr
element in that scope 'cause the whole row is being removed but the next 2 lines doesn't work. The table isn't being removed.
EDIT
I changed the if($(this).closest('table').find('tbody').is(':empty'))
to if(!$(this).closest('table').find('tbody').is(':empty'))
(exclamation mark) to see if it removes and it removed the whole table, but I inspected the table element before and after deleting the last row and got this
JS says that tbody is not empty, google chrome says otherwise. I don't know how to fix it