I was trying to do this in an alert box only to find out that I can’t now. I cannot manage to get this to display at all. Instead of the variable I get [object HTMLImageElement]. I am missing something but what is it?
function joePic(){
var joe_fat = new Image;
joe_fat.src = "pic1.jpg";
document.getElementById('photo').innerHTML = joe_fat;
}
<input type="button" value="Click here it find out" name="joePhoto" onclick="joePic()"
height="150" width="150" />
Well, you’re trying to assign an
Imageas HTML, but it’s not HTML. It’s anImage.You have two options:
Append
joe_fatinto the#photoelement using the proper DOM function (which isappendChild) instead of pretending it’s a string of HTML:Get rid of the
Imageobject and actually do present a string of HTML instead: