I thought this would be rather simple but it seems the empty method is not working to clear out a tbody that I have. I would appreciate if anyone knows a proper way to do this, I just want to delete everything contained within the tbody. So far I am trying:
$("#tbodyid").empty();
HTML:
<table> <tbody id="tbodyid"> <tr><td>something</td></tr> </tbody> </table>
NOTE: I am trying to do this to integrate with a plugin written by someone else that I am being made to use for a project. I am generating new <tr><td>new data</td></tr>
server-side and want to just be able to wipe out the existing table rows and replace them on AJAX callbacks.
click(function(){ $("#myTable"). find("tr:gt(0)"). remove(); }); });
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.
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.
If you want to remove the tbody tag, you could select the row itself rather than the table, then use the removeChild function.
jQuery:
$("#tbodyid").empty();
HTML:
<table> <tbody id="tbodyid"> <tr> <td>something</td> </tr> </tbody> </table>
Works for me
http://jsfiddle.net/mbsh3/
You probably have found this out already, but for someone stuck with this problem:
$("#tableId > 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