Menu
I’m dynamically creating a div and adding an image to it. When I set the image using a string like the code below, it works fine, the image appears.
[code]
newdiv.innerHTML = “<img src=’Images//gallery3.jpg’ />”;
document.body.appendChild(newdiv);
however when I use a variable like in the code below it doesn’t work, even though the variable is set to the same string as the one above. It just outputs the text < img src =’Images//gallery3.jpg’ />.
[code]
var image = ‘< img src =” + imageFile + ” />’;
newdiv.innerHTML = image;
document.body.appendChild(newdiv);
Anybody able to explain why it’s not working?