Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove all rows of the table but keep the header

I want to remove all rows of my table except the header.

This is what I've tried but it always deletes all rows and header:

$("#<%=tblDetailFourn.ClientID%> tbody tr").remove();

$("#<%=tblDetailFourn.ClientID%> tbody tr").not("thead tr").remove();

$("#<%=tblDetailFourn.ClientID%> tr").not("thead tr").remove();

$("#<%=tblDetailFourn.ClientID%> tbody").not("thead").remove();

$("#<%=tblDetailFourn.ClientID%> tbody").remove();

$("#<%=tblDetailFourn.ClientID%> > tbody").remove();

Here's the html:

<table id="tblDetailFourn" runat="server" class="ProjetTable ProjetTableHover">
    <thead>
       <tr>
          <th style="width:200px">Rôle de Ressource</th>
          <th style="width:200px">Nom Prénom</th>
          <th style="width:120px">Tel</th>
          <th style="width:200px">Courriel</th>
          <th style="width:80px">Actif</th>
          <th style="width:33px"></th>
          <th style="width:33px"></th>
      </tr>
    </thead>
    <tbody>
    </tbody>
</table>
like image 551
Marc Avatar asked Feb 23 '12 19:02

Marc


People also ask

How do I delete all rows except the first header in Excel?

In the Microsoft Visual Basic for Applications window, click Insert > Module. Then copy and paste the following VBA code into the Code window. 3. Press the F5 key to run the code, then all rows except the first header row are deleted from the active worksheet immediately.

Which command is used to remove all the row from a table?

SQL Truncate is a data definition language (DDL) command. It removes all rows in a table.


1 Answers

$('#tblDetailFourn tbody').empty();
like image 55
Jorge Avatar answered Sep 21 '22 17:09

Jorge