Error in Each function in jquery

Posted by Klbaiju under jQuery on 12/24/2014 | Points: 10 | Views : 1143 | Status : [Member] | Replies : 0
Hi ,

in my application data will display in gridview, using jquery function i have checked each cell.and add an anchor tag with an id inside of each cell.

following is working code

var firstcelltext;

$("#gridtable tr td").filter(":not(td:first-child)").each(function () {
firstcelltext = $(this).parent().find("td:first-child").text();
var fcelltext = firstcelltext.replace(/ /g, '-');
var colindex = $(this).closest("tr td").prevAll("tr td").length;
var headertext = $("table[id*=gridtable] th").eq(colindex).text();
var cellText = $(this).text();
if ($.trim(cellText) == '') {
$(this).css('background-color', 'Red');

$(this).append("<a class='anchor1' id='" + headertext + "-" + fcelltext + "' href='#'>N</a>");

else {

$(this).append("<a class='anchor2' id='" + headertext + "-" + fcelltext + "' href='#' >Y</a>");
$(this).css('background-color', 'LightGreen');


each cell rendered like this

<a id="11-01-Jan-2015" class="anchor1" href="#">N</a>. this is fine for my application.

my requirement is i want to use above code in html table.

i tried same code but cell is rendered like this

<a id="11 -01-Jan-2015-" class="anchor1" href="#">N</a>

there is a slight difference. in second output. an extra hyphen is added and a space between 11 and 01 as it rendered .

another problem is following code working fine in gridview but not in table

$(' .anchor1').click(function () {



how to solve both problems.




(No response found.)

Login to post response