MakeUseOf Answers

Kenny Goodmans Blog

What going on around the world?

Israeli stocks on Wall St

Thursday, July 28, 2011

Creating an image in javascript | Michael Fields

Creating an image in javascript | Michael Fields: "use javascript to work with images marked up in the body of an html document, but sometimes it is necessary to dynamically load them. I’ll do my best to explain how to do this.


To create a new image element in javascript we will use the Image() constructor.

1
var img = new Image();
Not much happens when you run this code. All we are doing is creating a new image object named img. To prove this, we can count the number of images in the document both before and after we created the new image object. Here’s how to do it:"

No comments:

Post a Comment

Creative Licence