Image src Property
Example
Change the URL of an image:
document.getElementById("myImg").src = "hackanm.gif";
Try it Yourself »
Description
The src property sets or returns the value of the src attribute of an image.
The required src attribute specifies the URL of an image.
Note: The src property can be changed at any time. However, the new image inherits the height and width attributes of the original image, if not new height and width properties are specified.
Browser Support
Property | |||||
---|---|---|---|---|---|
src | Yes | Yes | Yes | Yes | Yes |
Syntax
Return the src property:
imageObject.src
Set the src property:
imageObject.src = URL
Property Values
Value | Description |
---|---|
URL |
Specifies the URL of the image. Possible values:
|
Technical Details
Return Value: | A String, representing the URL of the image. Returns the entire URL, including the protocol (like http://) |
---|
More Examples
Related Pages
HTML reference: HTML <img> src attribute
❮ Image Object
Copyright 1999-2023 by Refsnes Data. All Rights Reserved.