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.
jQuery:
HTML:
Works for me
http://jsfiddle.net/mbsh3/
use this command to clear the body of that table:
$("#table_id tbody").empty()
I use jquery to load the table content dynamically, and use this command to clear the body when doing the refreshing.
hope this helps you.
Without use ID (
<tbody id="tbodyid">
) , it is a great way to cope with this issuePS:To remove specific row number as following example
or
Example for Remove table header or table body with jquery
you can use the
remove()
function of the example below and build table again with table head, and table bodyYou probably have found this out already, but for someone stuck with this problem: