Deleting table element when it has no tr element inside tbody
<p>I have this table structure</p>

<pre><code>&lt;table id="latest" class="debt"&gt;
    &lt;thead&gt;
    &lt;tr&gt;
        &lt;th width="50"&gt;Credor&lt;/th&gt;
        &lt;th width="50"&gt;Devedor&lt;/th&gt;
        &lt;th&gt;Motivo&lt;/th&gt;
        &lt;th width="80"&gt;Valor&lt;/th&gt;
        &lt;th width="10"&gt;&lt;/th&gt;
    &lt;/tr&gt;
    &lt;/thead&gt;
    &lt;tbody&gt;
    &lt;?php foreach ($this-&gt;latest as $latest) { ?&gt;
        &lt;tr &lt;?php if ($latest-&gt;reg_value &lt; 0) { echo "class='error'"; } ?&gt;&gt;
        &lt;td&gt;&lt;?php echo $latest-&gt;findParentRow('Application_Model_DbTable_Names','Creditor')-&gt;nam_name; ?&gt;&lt;/td&gt;
        &lt;td&gt;&lt;?php echo $latest-&gt;findParentRow('Application_Model_DbTable_Names','Debtor')-&gt;nam_name; ?&gt;&lt;/td&gt;
        &lt;td&gt;&lt;?php echo $latest-&gt;reg_reason; ?&gt;&lt;/td&gt;
        &lt;td&gt;R$ &lt;?php echo number_format(abs($latest-&gt;reg_value), 2, ',', ' ')?&gt;&lt;/td&gt;
        &lt;td&gt;&lt;a href="#" id="&lt;?php echo $latest-&gt;reg_id; ?&gt;" class="delete"&gt;&lt;img src="http://192.168.0.102/libraries/css/blueprint/plugins/buttons/icons/cross.png" alt=""/&gt;&lt;/a&gt;&lt;/td&gt;
        &lt;/tr&gt;
    &lt;?php } ?&gt;
    &lt;/tbody&gt;
&lt;/table&gt;
</code></pre>

<p>each row has a delete button which uses AJAX and removes the tr element itself. What happens is: it may happen the tbody become empty when all rows are deleted, when this happens I'd like to delete all the table.</p>

<p>I know there is a pseudo-selector <code>$('#latest tbody:empty')</code>but this selects only the tbody. I want to select the whole table when the tbody is empty or something like it.</p>

<h2>EDIT after answers</h2>

<p>I inspected the element after deleting all rows: there's only  and the thead tag inside the  tag. Still, it didn't removed the table element. Look at the code</p>

<pre><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;
});
</code></pre>
