causita causita - 1 year ago 66
Javascript Question

How to clear the data only from table cells with Jquery?

I have a predefined empty table. In my Ajax call I fill it with the required data. When the users tries to query for new information, I need to clear the data from the cells but leave the rows and cells structure.

for example .remove() and empty() does not work for me as it remove all rows.

I tried

$("#tblManifest tbody tr td").innerHTML=""
but that did not work. I only need to clear the cell's data from the tbody.

Answer Source

You need to really read the manual. The below code will work:

$("#tblManifest tbody tr td").html("");        // Or
$("#tblManifest tbody tr td").html(" ");  // Add a non-breaking space. (Recommended)
$("#tblManifest tbody tr td").empty();         // This