Click to See Complete Forum and Search --> : Show image created using new


bon
12-15-2003, 05:24 PM
Hi,

I would like to create one or more Images and then have them displayed on my page. I was hoping to be able to do something like


//Create image
var img = new Image();
img.src = "pic.jpg";
img.onClick = myFunc;

//Display image on page
document.images.length++;
document.images[document.images.length-1] = img;



or even better, if some kind of overloaded document.write existed, I would like to be able to achieve what one might expect from


var img = new Image();
img.src = "pic.jpg";
img.onClick = myFunc;

document.write(img);


As I am new to JavaScript, the suggestions above are wild guesses and they are just provided in an attempt to explain what functionality I am searching for - I have no idea if they even remotely resemble the correct solution, although I have tried them and found that they had no observable effect.

Kind regards,
Bon