Attribute value Property - Change the value of the src attribute of an <img> element: - Javascript DOM

Javascript examples for DOM:Attribute

Description

Attribute value Property - Change the value of the src attribute of an <img> element:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<img src="http://java2s.com/resources/a.png" width="100" height="180">

<button onclick="myFunction()">change the src attribute's value of the image above</button>

<script>
function myFunction() {/*  w  ww  .  j a v a2  s.  c o m*/
    var x = document.getElementsByTagName("IMG")[0];
    x.getAttributeNode("src").value = "http://java2s.com/resources/d.png";
}
</script>

</body>
</html>

Related Tutorials