I have an HTML table filled with a number of rows.
How can I remove all the rows from the table?
The jQuery remove() method is used to remove a row from HTML table. jQuery remove() Method: This method removes the selected elements alongwith text and child nodes. This method also removes data and events of the selected elements.
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').
This can be done by using JavaScript. First of all set the ID or unique class to the table. Select the table element and use remove() or detach() method to delete the all table rows.
$(this). toggle(enableRows, disableRows);
Use .remove()
$("#yourtableid tr").remove();
If you want to keep the data for future use even after removing it then you can use .detach()
$("#yourtableid tr").detach();
If the rows are children of the table then you can use child selector instead of descendant selector, like
$("#yourtableid > tr").remove();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With