Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

HTML | DOM value Property

  • Last Updated : 12 Aug, 2021

The DOM value property in HTML is used to set or return the value of any attribute.
Syntax: 
 

  • It returns the attribute value. 
     
attribute.value
  • It is used to set a value to the property. 
     
attribute.value = value

Property Value: 

Attention reader! Don’t stop learning now. Get hold of all the important HTML concepts with the Web Design for Beginners | HTML  course.

  • value: It defines the value of the attribute.

Return Value:  It returns a string value which represents the value of the attribute. 

Below program illustrates the DOM value property in HTML:
Example: 
 



html




<!DOCTYPE html>
<html>
    <head>
        <title>
            DOM Value Property
        </title>
         
        <!-- script to change property value -->
        <script>
            function myFunction() {
                var x = document.getElementsByTagName("IMG")[0];
                x.getAttributeNode("src").value =
            }
        </script>
    </head>
     
    <body style = "text-align:center">
         
        <h1 style = "color:green;">
            GeeksforGeeks
        </h1>
         
        <h2>DOM Value Property</h2>
         
        <img src =
        width="180" height="180">
         
         
<p>
           Click the button to change the value
           of attribute "src" of the image.
        </p>
 
         
        <!-- Button to change DOM value property -->
        <button onclick = "myFunction()">
            Try it
        </button>
    </body>
</html>                          

Before Click on the button: 
 

After clicking on the button: 
 

Supported Browsers: The browser supported by DOM value property are listed below: 
 

  • Google Chrome
  • Internet Explorer
  • Firefox
  • Opera
  • Safari

 




My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!