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 starts when I want to delete a table row using the delete button (as shown in the image) image http://aviary.com/viewfull?fguid=433f68f6-d18d-102d-a9f3-0030488e168c&nowatermark=true
It may happen that the table becomes empty from the rows of the table. I want to delete the whole table when this happens, but the table is not deleted. String Code $(this).remove(); works, and this seems to refer to the tr element in this scope because the whole line is deleted, but the next two lines do not work. The table is not deleted.
EDIT
I changed if($(this).closest('table').find('tbody').is(':empty')) to if(!$(this).closest('table').find('tbody').is(':empty')) (exclamation point) to see if he deleted and deleted the whole table, but I checked the table element before and after deleting the last row and got this
image http://rookery9.aviary.com.s3.amazonaws.com/4344000/4344383_4fbd.png
JS says tbody is not empty, google chrome says otherwise. I do not know how to fix this.
javascript jquery ajax
Rodrigo Souza
source share