使用.append后检查元素是否为空

use*_*530 2 jquery

我想tbody使用jQuery 检查表body()是否为空.到目前为止,我尝试过类似的东西:

$("#searchTable tbody").is(":empty")
Run Code Online (Sandbox Code Playgroud)

但它不起作用.还有其他想法吗?

HTML示例

<table id="searchTable" cellpadding="0" cellspacing="0" width="100%">
    <thead>
        <tr>
            <th>No.</th>
            <th><a href="#">Status</a></th>
            <th><a href="#" class="asc">Category</a></th>
            <th><a href="#" class="desc">Title</a></th>
            <th><a href="#" class="desc">Last Used</a></th>
            <th><a href="#" class="desc">URL</a></th>
            <th style="width: 96px;">Actions</th>
        </tr>
    </thead>
    <tbody></tbody>
</table>
Run Code Online (Sandbox Code Playgroud)

所以我想检查tbody中是否附加了某些内容; 如果没有,那么提醒一些事情.

Bob*_*Bob 7

你可以试试像

$('#searchTable tbody').children().length;
Run Code Online (Sandbox Code Playgroud)

如果tbody为空(没有孩子),则为0.