jQuery delete all table rows except first

后端 未结 14 1359
失恋的感觉
失恋的感觉 2021-01-29 17:40

Using jQuery, how do I delete all rows in a table except the first? This is my first attempt at using index selectors. If I understand the examples correctly, the following sh

14条回答
  •  攒了一身酷
    2021-01-29 18:16

    Another way to accomplish this is using the empty() function of jQuery with the thead and tbody elements in your table.

    Example of a table:

    Col1Col2
    somecontent
    to beremoved

    And the jQuery command:

    $("#tableId > tbody").empty();
    

    This will remove every rows contained in the tbody element of your table and keep the thead element where your header should be. It can be useful when you want to refresh only the content of a table.

提交回复
热议问题