Example
Return the value of the value attribute of a button:
var x = document.getElementById("myBtn").value;
The result of x will be:
myvalue
Try it Yourself »
Definition and Usage
The value property sets or returns the value of the value attribute of a button.
The value attribute specifies the underlying value that is associated with a button.
Important: If you use the <button> element in an HTML <form>, different browsers will submit different values. Internet Explorer will submit the text between the <button> and </button> tags, while other browsers will submit the content of the value attribute.
Browser Support
The value property is supported in all major browsers.
Syntax
Return the value property:
buttonObject.value
Set the value property:
buttonObject.value=text
Property Values
Value | Description |
---|---|
text | The initial value of the button |
Technical Details
Return Value: | A String, representing the underlying value that is associated with the button |
---|
More Examples
Example
Change the value of the value attribute of a button:
document.getElementById("myBtn").value = "newButtonValue";
Try it Yourself »
Related Pages
HTML reference: HTML <button> value attribute
< Button Object