I thought this might be a fast way to remove the contents of a very large table (3000 rows):
$jq("tbody", myTable).remove();
But it's taking around five seconds to complete in firefox. Am I doing something dumb (aside from trying to load 3000 rows in to a browser)? Is there faster way to do it?
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. Parameters: It accepts single parameter selector which is optional.
The jQuery function removes all the rows except the first one using the remove() method. Syntax: $('#btn').
remove() method we can dynamic add and delete row using jquery. append() method is used for append or add rows inside an HTML table and . remove() method to remove or delete table rows as well as all data inside it from the DOM dynamically with jquery.
$("#your-table-id").empty();
That's as fast as you get.
It's better to avoid any kind of loops, just remove all elements directly like this:
$("#mytable > tbody").html("");
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