HTML | DOM Button value Property

The DOM Button value Property is used to set or return the value of the value attribute of a button element. The value attribute for <button> element in HTML is used to specify the initial value of the button element.

Syntax:

  • It is used to return the value property.
    buttonObject.value
  • It is used to set the value property.
    buttonObject.value = text

Property Values:



  • text: It specify the initial value of the Button.

Return Value: It returns a string value which represent the initial value of the button.

Example-1: This Html program illustrate how to return the value Property.

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
  
<head>
    <title>DOM button value Property
    </title>
  
</head>
  
<body style="text-align:center">
    <h1 style="color:green;"
            GeeksforGeeks 
        </h1>
  
    <h2
            DOM button value Property 
        </h2>
  
    <button id="btn" 
            value="GeeksforGeeks" 
            onclick="geek()">
        Click me!
    </button>
  
    <p id="g"
       style="font-size:25px;color:green;">
  </p>
  
    <script>
        function geek() {
  
            var x =
                document.getElementById("btn").value;
            document.getElementById("g").innerHTML =
                x;
        }
    </script>
</body>
  
</html>

chevron_right


Output:

Before Clicking On Button:

After Clicking On Button:

Example-2: This HTML program illustrate how to set the value Property.

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
  
<head>
    <title>DOM button value Property
  </title>
</head>
  
<body style="text-align:center">
    <h1 style="color:green;"
            GeeksforGeeks 
        </h1>
  
    <h2
            DOM button value Property 
        </h2>
  
    <button id="btn"
            value="User" 
            onclick="geek()">
        Click me!
  </button>
  
    <p id="g" 
       style="font-size:25px;
              color:green;">
  </p>
  
    <script>
        function geek() {
            var x = 
                document.getElementById("btn").value = 
                "GeeksForGeeks"
            document.getElementById("g").innerHTML = 
              "The value has been changed from user to " +
              x;
        }
    </script>
</body>
  
</html>

chevron_right


Output:

Before Clicking On Buttton:

After Clicking On Button:

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

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


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

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.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.