I am trying to run the following code but it doesn’t seem to select the td by id correctly:
var table = $('<table/>').attr('cellspacing', '2px');
for (var r = 0; r < length; r++) {
var trow = $("<tr/>");
for (var c = 0; c < length; c++) {
var cellText = $('<div/>').html(texts[r][c]).text();
$("<td/>").addClass("cell").attr('id', 'td' + r + c).text(cellText).appendTo(trow);
}
trow.appendTo(table);
}
$('body').append(table);
alert($("#td00").text());
The alert in the end come out empty, although the texts array contains data. What is the correct way to select the td / extract the text? I need it because I wan’t to add rowspan of 2 to some of the td’s but can’t seem to select them properly.
1 Answer