IMG.src (Property)

The URL where the image can be loaded from.

Availability:

DOM level - 1
JavaScript - 1.5
JScript - 3.0
Internet Explorer - 4.0
Netscape - 3.0
Property/method value type:String primitive
JavaScript syntax:-myIMG.src

If you change the src property of an image it will be replaced on the browser's display screen. The only limitation is that the images that are replaced are exactly the same shape and size as the previous image.

Some browsers may forgive you if you display differently sized images, some may scale the images to fit.

Changing the src property of an image can lead to all manner of creative effects such as rollover highlights, clocks, animations, progress bars etc. You can also simulate checkboxes graphically as well as all manner of other useful and 'pretty' user interface widgets.

For animations to work smoothly, you should ensure that the images have been cached locally first, otherwise the animation will appear somewhat jerky while they are fetched from a server.

See also:Image.src, IMG.href