HTML | DOM Input Image alt Property
The HTML DOM Input Image alt Property is used set or return the value of the alt attribute of an Input Image. The alt Attribute is used to specify the alternate text for an image. It is useful when the image not displayed. It is used to give alternative information for an image.
Syntax:
imageObject.alt
imageObject.alt = text
Property value: It contains the value i.e. text which specify alternative text for an input Image.
Return value: It returns a string value which represents an alternative text for an Input Image.
Example 1: This Example returns the alt property.
<!DOCTYPE html> <html> <head> <title> HTML DOM Input Image alt Property </title> </head> <body style="text-align:center;"> <h1 style="color:green;"> GeeksforGeeks </h1> <h4> DOM Input Image alt Property </h4> <input id="myImage" formEnctype="application/x-www-form-urlencoded" type="image" formtarget="#" src= alt="Geeks_Logo" width="48" height="48" formMethod="post" autofocus> <br> <br> <button onclick="my_geek()">Submit </button> <h2 id="Geek_h" style="color:green;"></h2> <script> function my_geek() { // set Disabled Property. var txt = document.getElementById( "myImage").alt; document.getElementById( "Geek_h").innerHTML = txt; } </script> </body> </html> |
Output:
- Before Clicking On Button:

- After Clicking On Button:
Example 2: This Example sets the alt Property.
<!DOCTYPE html> <html> <head> <title> HTML DOM Input Image alt Property </title> </head> <body style="text-align:center;"> <h1 style="color:green;"> GeeksforGeeks </h1> <h4> DOM Input Image alt Property </h4> <input id="myImage" formEnctype="application/x-www-form-urlencoded" type="image" formtarget="#" src= alt="Geeks_Logo" width="48" height="48" formMethod="post" autofocus> <br> <br> <button onclick="my_geek()">Submit </button> <h2 id="Geek_h" style="color:green;"> </h2> <script> function my_geek() { // set Disabled Property. var txt = document.getElementById( "myImage").alt = "submit"; document.getElementById( "Geek_h").innerHTML = "The alt Attribute was changed to " + txt; } </script> </body> </html> |
Output:
- Before Clicking On Button:

- After Clicking On Button:

Supported Browsers: The browsers supported by HTML DOM Input Image alt Property are listed below:
- Googl Chrome 10.0
- Firefox 4.0
- Opera 11.0
- Safari 5.1
Recommended Posts:
- HTML | DOM Input Image name Property
- HTML | DOM Input Image value Property
- HTML | DOM Input Image src Property
- HTML | DOM Input Image type Property
- HTML | DOM Input Image formEnctype Property
- HTML | DOM Input Image formTarget Property
- HTML | DOM Input Image width Property
- HTML | DOM input image height Property
- HTML | DOM Input Image form Property
- HTML | DOM Input Image formNoValidate Property
- HTML | DOM Input Image disabled Property
- HTML | DOM Input Image formAction Property
- HTML | DOM Input Image formMethod Property
- HTML | DOM Input image autofocus Property
- HTML | DOM Input Image Object
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


