This page is Almost Ready

Notice: The WebPlatform project, supported by various stewards between 2012 and 2015, has been discontinued. This site is now available on github.

Image

Summary

Legacy. Use document.createElement(“img”) instead. Quickly constructs an img element.

Overview

A shorter legacy constructor for creating and loading images.

Properties

No properties.

Methods

No methods.

Events

No events.

Examples

The following script creates a new image and appends it to the body element.

var img = new Image(50, 50);
img.src = "image.png";
document.body.appendChild(img);

Usage

 Use this constructor as a shorter way to instantiate new img elements before adding them to the document.

Syntax -

new Image(width, height)

You can specify up to two optional arguments:

||
|width|Optional. Integer that specifies the img width.|
|height|Optional. Integer that specifies the img height.|

Notes

The loading process of the image starts as soon as its src property is set, even when not added to a document.

Related specifications

WHATWG HTML
Living Standard
HTML5
Last Call Working Draft

Attributions