Get Image Element - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Image


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>

<img id="myImg" src="" alt="alt message" width="304" height="200">

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

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

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


Related Tutorials