javascript - Adding image to table given link -
i have following code goes through rows , columns
(var j=0; j < cols; j++) { (var k=0; k < cols; k++) { alert(data[j][i]) if(data[j][i].endswith(".jpg")) { var img = document.createelement('img'); img.src = data[j][i]; img.onload = function() { //check make sure tabledata += '<td>' + img + '</td>'; }; } else { tabledata += '<td>'+data[j][i]+'</td>'; } break; } }
i trying create images nothing pops in spot. idea might doing wrong? tried without .onload , pops [object htmlimageelement]
- variable
img
hold object, nothtml
string. use<img>
tagstring
instead! - also note
onload
event async, callback invoke later!
for (var j = 0; j < cols; j++) { (var k = 0; k < cols; k++) { alert(data[j][i]) if (data[j][i].endswith(".jpg")) { var img = '<img src="' + data[j][i] + '">'; tabledata += '<td>' + img + '</td>'; } else { tabledata += '<td>' + data[j][i] + '</td>'; } break; } }
Comments
Post a Comment