Latest web development tutorials

HTML DOM Image src attribute

Image Object Reference Image Object

Definition and Usage

src property sets or returns the image src attribute value.

src attribute specifies the URL of a graph.

grammar

imageObject.src=URL


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the src attribute


Examples

Examples

<html>
<head>
<script>
function changeSrc()
{
document.getElementById("myImage").src="hackanm.gif";
}
</script>
</head>
<body>

<img id="myImage" src="compman.gif" width="107" height="98">
<br><br>
<input type="button" onclick="changeSrc()" value="Change image">

</body>
</html>

try it"


Image Object Reference Image Object