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.
<!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> |
Output:
Before Clicking On Button:

After Clicking On Button:

Example-2: This HTML program illustrate how to set the value Property.
<!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> |
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
Recommended Posts:
- HTML | DOM Button name Property
- HTML | DOM Button autofocus Property
- HTML | DOM Input Button value Property
- HTML | DOM Button type Property
- HTML | DOM Input Button name Property
- HTML | DOM Button formNoValidate Property
- HTML | DOM Button disabled Property
- HTML | DOM Button formEnctype Property
- HTML | DOM Button formTarget Property
- HTML | DOM Button formAction Property
- HTML | DOM Button form Property
- HTML | DOM Button formMethod Property
- HTML | DOM Input Button form Property
- HTML | DOM Input Button disabled Property
- HTML | DOM Input Button autofocus Property
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.


