How to remove all rows from a table in JavaScript ? Last Updated : 18 Dec, 2023 Comments Improve Suggest changes Like Article Like Report Given an HTML document that contains an HTML table, the task is to remove all rows from the HTML table. Removing all rows is different from removing a few rows. This can be done by using JavaScript. Here we have two Approaches to removing all rows from a table: Table of Content Using remove() methodUsing detach() method Approach 1: Using remove() methodThe remove() method in JQuery is used to remove all the selected elements including all the text. This method also removes data and all the events of the selected elements. First of all, set the ID or unique class to the table.Select the table element and use the remove() method to delete all table rows.Example: In this example, All rows are deleted by using the remove() method. html <!DOCTYPE html> <html> <head> <script src= "https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"> </script> </head> <body> <h1 style="color:green;"> GeeksforGeeks </h1> <table id="table"> <colgroup> <col id="myCol" span="2"> <col style="background-color:green"> </colgroup> <tr> <th>S.No</th> <th>Title</th> <th>Geek_id</th> </tr> <tr id="row1"> <td>Geek_1</td> <td>GeekForGeeks</td> <th>Geek_id_1</th> </tr> <tr> <td>Geek_2</td> <td>GeeksForGeeks</td> <th>Geek_id_2</th> </tr> <tr> <td>Geek_3</td> <td>GeeksForGeeks</td> <th>Geek_id_3</th> </tr> <tr> <td>Geek_4</td> <td>GeeksForGeeks</td> <th>Geek_id_4</th> </tr> </table> <br> <button onclick="Geeks()"> Click here </button> <p id="GFG_DOWN"> </p> <script> function Geeks() { $("#table").remove(); $("#GFG_DOWN").text ("All rows of the table are deleted."); } </script> </body> </html> Output: How to remove all rows from a table in JavaScript ?Approach 2: Using detach() method Detach method is used to remove the selected element, with all texts and child nodes, leaving only data and events. the elements that are removed using this technique are saved in copy so they can be reinserted at a later time as needed. Example: In this example, All rows are deleted by using detach() method. html <!DOCTYPE html> <html> <head> <script src= "https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"> </script> </head> <body> <h1 style="color:green;"> GeeksforGeeks </h1> <table id="table"> <colgroup> <col id="myCol" span="2"> <col style="background-color:green"> </colgroup> <tr id="thead"> <th>S.No</th> <th>Title</th> <th>Geek_id</th> </tr> <tr id="row1"> <td>Geek_1</td> <td>GeekForGeeks</td> <th>Geek_id_1</th> </tr> <tr> <td>Geek_2</td> <td>GeeksForGeeks</td> <th>Geek_id_2</th> </tr> <tr> <td>Geek_3</td> <td>GeeksForGeeks</td> <th>Geek_id_3</th> </tr> <tr> <td>Geek_4</td> <td>GeeksForGeeks</td> <th>Geek_id_4</th> </tr> </table> <br> <button onclick="Geeks()"> Click here </button> <p id="GFG_DOWN" style="color:green; font-size: 20px; font-weight: bold;"> </p> <script> function Geeks() { $('#table').detach(); $("#GFG_DOWN").text ("All rows of the table are deleted."); } </script> </body> </html> Output: How to remove all rows from a table in JavaScript ? Comment More infoAdvertise with us Next Article How to remove all rows from a table in JavaScript ? P PranchalKatiyar Follow Improve Article Tags : JavaScript Web Technologies JavaScript-Questions Similar Reads JavaScript - How to Sort Rows in a Table? Rows in a table are horizontal sections that hold data, organizing information across columns in a structured, easy-to-read format. To sort table rows in JavaScript, create a function that compares rows based on cell values. Use a loop to check and swap rows as needed until all rows are in order.App 4 min read How to remove the table row in a table using JavaScript ? Removing a table row in JavaScript involves targeting the row element by its index or unique identifier, then using the remove() method to delete it from the DOM. This updates the table dynamically without requiring a page reload. This can be done in two ways: Table of Content JavaScript remove() Me 3 min read How to Remove Column from HTML Table using JavaScript ? Given an HTML table and the task is to remove the certain column from the HTML table. There are two approaches that are discussed below: Approach 1: First, select the table and also get the rows of table using table.rows. Get the number of columns of a row and go through each one of the columns. Use 3 min read How to Remove a Specific Item from an Array in JavaScript ? Given an Array, the task is remove specific item from an array in JavaScript. It means we have an array with N items, and remove a particular item from array.ExamplesInput: Arr = [ 10, 20, 30, 40, 50, 60 ] removeItem = 40 Output: [ 10, 20, 30, 50, 60 ]Table of ContentUsing splice() MethodUsing filte 3 min read How to Insert a Row in an HTML Table in JavaScript ? In JavaScript, we can insert a row dynamically in the HTML table using various approaches. JavaScript provides us with different methods to accomplish this task as listed below. Table of Content Using insertRow() and insertCell()Using insertAdjacentHTML()Using insertRow() and insertCell()In this app 2 min read Like