Name
Image — an <img> in an HTML document
Inherits from
Node, Element
Synopsis
An Image object represents an image embedded in an HTML
document with an <img>
tag.
The images that appear in a document are collected in the document.images[]
array.
The src
property of the
Image object is the most interesting one. When you set this
property, the browser loads and displays the image specified by the
new value. This allows visual effects such as image rollovers and
animations. See Scripting Images for
examples.
You can create offscreen Image objects by simply creating new
<img>
elements with document
.createElement()
or with
the Image()
constructor. Note
that this constructor does not have an argument to specify the image
to be loaded: to load an image, simply set the src
property of your Image object. To
actually display the image, insert the Image object into the
document.
Constructor
new
Image
([
unsigned
long
width
,
unsigned
long
height
])
You can create a new Image as you would create any HTML
element with document.
create
Element()
. For
historical reasons, however, client-side JavaScript also defines the
Image()
constructor to do the
same thing. If the width
or
height
arguments are specified, they set
the width
and height
attributes of the <img>
tag.
Properties
In addition to the properties listed here, Image elements also
expose the following HTML attributes as JavaScript properties:
alt
, usemap
, ismap
.
readonly boolean
complete
true
if no imagesrc
was specified or if the image has been completely ...
Get JavaScript: The Definitive Guide, 6th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.