Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App
geeksforgeeks
Browser
Continue

Related Articles

HTML | DOM Input Image src Property

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

The Input Image src Property is used to sets or returns the value of the src attribute of an Input Image. The src Attribute is used to specify the URL of the image to be used as a submit button. 

Syntax: 

It returns the src Property.

imageObject.src

It sets the src Property.

imageObject.src = "URL"

Property Values: It contains a single value URL which specifies the link of source image. There are two types of URL link which are listed below:

  • Absolute URL: It points to another webpage.
  • Relative URL: It points to other files of the same web page.

Return Value: It returns a string value which represents the URL of the Input Image. 

Example-1: This Example returns a Input Image src Property. 

HTML




<!DOCTYPE html>
<html>
<head>
    <title>
        HTML DOM Input Image src Property
    </title>
</head>
<body style="text-align:center;">
    <h1 style="color:green;">
            GeeksForGeeks
    </h1>
    <h2>DOM Input Image src Property</h2>
    <button onclick="my_geek()">
        <input id="myImage"
            value="myGeeks"
            type="image"
            src=
            alt="Submit"
            formaction="#"
            formtarget="#"
            formenctype="text/plain"
            width="48"
            height="48">
    </button>
    <h2 id="Geek_h"
        style="color:green;">
 
    </h2>
    <script>
        function my_geek() {
 
            // Return src Property
            var txt = document.getElementById(
                "myImage").src;
            document.getElementById(
                "Geek_h").innerHTML = txt;
        }
    </script>
</body>
</html>

Output: Before Clicking On Button:

  

After Clicking On Button:

  

Example-2 This Example sets the Input Image src Property. 

HTML




<!DOCTYPE html>
<html>
<head>
    <title>
        HTML DOM Input Image src Property
    </title>
</head>
<body style="text-align:center;">
 
    <h1 style="color:green;">
        GeeksForGeeks
    </h1>
    <h2>DOM Input Image src Property</h2>
    <button onclick="my_geek()">
        <input id="myImage"
            value="myGeeks"
            type="image"
            src=
            alt="Submit"
            formaction="#"
            a formtarget="#"
            formenctype="text/plain"
            width="48"
            height="48">
    </button>
    <h2 id="Geek_h" style="color:green;">
    </h2>
    <script>
        function my_geek() {
 
            // change URL of image
            var txt = document.getElementById(
                "myImage").src =
             
            document.getElementById("Geek_h").innerHTML = txt;
        }
    </script>
</body>
</html>

Output: Before Clicking On Button:

  

After Clicking On Button:

  

Supported Browsers: The browsers supported by DOM Input Image src Property are listed below:

  • Google Chrome
  • Edge 12+
  • Firefox
  • Apple Safari
  • Opera

My Personal Notes arrow_drop_up
Last Updated : 26 Aug, 2022
Like Article
Save Article
Similar Reads
Related Tutorials