I have this table structure
<table id="latest" class="debt"> <thead> <tr> <th width="50">Credor</th> <th width="50">Devedor</th> <th>Motivo</th> <th width="80">Valor</th> <th width="10"></th> </tr> </thead> <tbody> <?php foreach ($this->latest as $latest) { ?> <tr <?php if ($latest->reg_value < 0) { echo "class='error'"; } ?>> <td><?php echo $latest->findParentRow('Application_Model_DbTable_Names','Creditor')->nam_name; ?></td> <td><?php echo $latest->findParentRow('Application_Model_DbTable_Names','Debtor')->nam_name; ?></td> <td><?php echo $latest->reg_reason; ?></td> <td>R$ <?php echo number_format(abs($latest->reg_value), 2, ',', ' ')?></td> <td><a href="#" id="<?php echo $latest->reg_id; ?>" class="delete"><img src="http://192.168.0.102/libraries/css/blueprint/plugins/buttons/icons/cross.png" alt=""/></a></td> </tr> <?php } ?> </tbody> </table>
each line has a delete button that uses AJAX and removes the tr element itself. What happens: it may happen that tbody becomes empty when all rows are deleted, when this happens, I want to delete the entire table.
I know that there is a pseudo-selector $('#latest tbody:empty') , but this only selects tbody. I want to select the whole table when the shadow is empty or something like that.
EDIT after replies
I checked the element after deleting all the lines: there and thead tag inside the tag. However, he did not delete the table element. Look at the 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; });
source share