Image src Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Image


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>

<img id="myImg" src="" width="107" height="98">

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

function myFunction() {/*from  www  . j a  v a 2  s  .c om*/
    document.getElementById("myImg").src = "";


Related Tutorials