Image src Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Image

Description

The src property sets or gets the src attribute of an image.

Set the src property with the following Values

Value Description
URL Sets the URL of the image.

Return Value

A String, representing the URL of the image.

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<img id="myImg" src="http://java2s.com/resources/a.png" width="107" height="98">

<button onclick="myFunction()">Test</button>

<script>
function myFunction() {/*from  www  . j a  v a 2  s  .c om*/
    document.getElementById("myImg").src = "http://java2s.com/resources/b.png";
}
</script>

</body>
</html>

Related Tutorials