Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

clear table jquery

I have an HTML table filled with a number of rows.

How can I remove all the rows from the table?

like image 384
learning Avatar asked Apr 12 '10 06:04

learning


People also ask

How to clear the table jQuery?

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.

How to Delete all rows of a table using jQuery?

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').

How do you clear a table in JavaScript?

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.

How to disable a row in table using jQuery?

$(this). toggle(enableRows, disableRows);


1 Answers

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(); 
like image 95
rahul Avatar answered Oct 07 '22 23:10

rahul