开发者

JQuery clear all rows after the first row?

Given the follow:

<table id="myTable">
  <tr> </tr>
  <tr> </tr>
  ...
</table>

I can clear the table by doing: $("myTable").html("");

But, I'd like to instead clear all ro开发者_运维问答ws but the first one. Any ideas?


$('#myTable tr:gt(0)').remove()


I think you are trying to remove all rows except for table header so why don't you create th as

<table id='my Table'>
    <tr>
        <th></th>
    </tr>
    <tr>
        <td></td>
    </tr>
    <tr>
        <td></td>
    </tr>
</table>

And Jquery as

 $('#myTable tr td').parents('tr').remove();


Another solution less elegant:

$('#myTable tr').not($('#myTable tr:first')).remove();


A bit inelegant:

$("#myTable").slice(1, 4).remove();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜