Image srcProperty
Image Object
Definition and Usage
The src property sets or returns the value of the src attribute of an image.
The src attribute specifies the URL of an image.
Syntax
imageObject.src=URL
Browser Support
![]()
![]()
![]()
![]()
![]()
All major browsers support the src attribute.
Example
Example
<html>
<head>
<script>
function changeSrc()
{
document.getElementById("myImage").src="hackanm.gif.html";
}
</script>
</head>
<body>
<img id="myImage" src="compman.gif.html" width="107" height="98">
<br><br>
<input type="button" onclick="changeSrc()" value="Change image">
</body>
</html>
<head>
<script>
function changeSrc()
{
document.getElementById("myImage").src="hackanm.gif.html";
}
</script>
</head>
<body>
<img id="myImage" src="compman.gif.html" width="107" height="98">
<br><br>
<input type="button" onclick="changeSrc()" value="Change image">
</body>
</html>
Try it Yourself »
Image Object Other Extensions