How to Delete All Table Rows Except First One using jQuery? Last Updated : 17 Oct, 2024 Comments Improve Suggest changes Like Article Like Report To delete all table rows except the first one using jQuery, you can target the rows and remove them while keeping the first row intact.ApproachFirst, we create a table using <table> tag and add a button containing btn id. When a user clicks on the button, then the jQuery function is called. The jQuery function removes all the rows except the first one using the remove() method.Syntax:$('#btn').click(function () { $("#rTable").find("tr:gt(0)").remove();});Example: HTML <!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <script src= "https://code.jquery.com/jquery-3.5.1.min.js"> </script> <style> table, th, td { border: 1px solid black; border-collapse: collapse; } th, td { padding: 20px; } </style> </head> <body> <h4> Delete all table rows except first one using jQuery </h4> <table style="width:50%" id="rTable"> <tr> <th>Firstname</th> <th>Lastname</th> <th>Age</th> </tr> <tr> <td>Priya</td> <td>Sharma</td> <td>24</td> </tr> <tr> <td>Arun</td> <td>Singh</td> <td>32</td> </tr> <tr> <td>Sam</td> <td>Watson</td> <td>41</td> </tr> </table> <br><br> <button id="btn"> Remove All Row Except First One </button> <script> $(document).ready(function () { $('#btn').click(function () { $("#rTable").find("tr:gt(0)").remove(); }); }); </script> </body> </html> Output: Comment More infoAdvertise with us Next Article How to Delete All Table Rows Except First One using jQuery? V vkash8574 Follow Improve Article Tags : JavaScript Web Technologies JQuery jQuery-Questions Similar Reads How to highlight alternate table row using jQuery ? In this article, we will set the highlight on an alternative table row using jQuery. The :nth-child(2n) selector is used to select the alternative row and the addClass() method is used to set the style of the alternative rows. Syntax: $(tr:nth-child(2n)").addClass("GFG"); Here, we will create a simp 2 min read How to select all even/odd rows in table using jQuery ? In this article, we will see how to make a table by selecting the alternate rows i.e. selecting the even or odd rows by clicking on the respective buttons. This feature can be useful at the time of selecting the specific data/elements of either of the rows or to highlight the table of data for displ 3 min read How to Add Edit and Delete Table Row in jQuery ? In this article, we will create an example of how to add, edit and delete table rows in jQuery. For creating this functionality we need to know about the basics of the HTML table, jQuery basic functionality. Table row: An HTML table is a combination of rows and columns. The table row is in the horiz 3 min read How to Dynamically Add/Remove Table Rows using jQuery? We will dynamically add/remove rows from an HTML table using jQuery. jQuery provides us with a lot of methods to perform various tasks. To dynamically add and remove the rows from an HTML table, we are also going to use some of these jQuery methods like append(), remove(), etc.Adding a rowTo add a r 3 min read How to Count Number of Rows and Columns in a Table Using jQuery? Given an HTML document containing a table, the task is to count the number of rows and columns in that table using JQuery. There are a few methods available in jQuery to count the number of rows and columns in an HTML table. Table of Content By iterating through the rows and columnsBy using the leng 3 min read Like