for (i=0;i<tar.length;i++) {
document.write("<img src=" + tar[i] + " width='100' height='100'>"+" ");
}
tar array has image sources, i want to display that using getElementById not by document.write
for (i=0;i<tar.length;i++) {
document.write("<img src=" + tar[i] + " width='100' height='100'>"+" ");
}
tar array has image sources, i want to display that using getElementById not by document.write
Using document.createElement
and appendChild
, you might do:
var myContainer = document.getElementById("someContainerId");
for (i=0;i<tar.length;i++) {
var myimg = document.createElement("img");
myimg.src= tar[i];
myimg.width="100";
myimg.height="100";
myContainer.appendChild(myimg);
}
Make sure, of course, that there really is a container element with the id of someContainerId
, or whatever id you want to give it. It might be best if the container element were a <div>
.