Get Image Element - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Image

Introduction

The Image object represents an HTML <img> element.

You can access an <img> element by using getElementById():

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<img id="myImg" src="http://java2s.com/resources/a.png" alt="alt message" width="304" height="200">

<button onclick="myFunction()">get the URL of the image</button>

<p id="demo"></p>

<script>
function myFunction() {//from www .  jav  a  2  s  . co m
    var x = document.getElementById("myImg").src;
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

Related Tutorials