Clear cell of html table using jquery

Posted by Klbaiju under jQuery on 8/21/2015 | Points: 10 | Views : 351 | Status : [Member] | Replies : 1

In my application iam using an html table for displaying data.

on the footer of table ,i want to display some data on the cells like this

var t1 = $('#GridViewProfit th');
for (var i = 0; i < t1.length - 1; i++) {

$("#GridViewProfit tr:last td").eq(i + 1).html(listId[i]).css('background-color', 'white');


here GridViewProfit is the name of html table.

my requirement is before executing this statement

$("#GridViewProfit tr:last td").eq(i + 1).html(listId[i]).css('background-color', 'white');

i want to clear the cell .means erase the previous value

i have tried these commands

$("#GridViewProfit tr:last td").eq(i + 1).html("");

$("#GridViewProfit tr:last td").eq(i + 1).val("");

but not working .

how to solve this




Posted by: Sheonarayan on: 8/23/2015 [Administrator] HonoraryPlatinum | Points: 25

Most likely your jQuery selector is not working that you have written to find out the table cell that is why the cell is not getting cleared. I can see that your code has a syntax error, there will be one more closing bracket like

$("#GridViewProfit tr:last td").eq(i + 1).html(listId[i]).css('background-color', 'white')); 

In this case even if you do not erase previous value, your new value will overwrite previous value so just see that your selector code is working fine that writes the new value.


Sheo Narayan

Klbaiju, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response