The value
attribute from button element
defines the text shown on the button.
The value
property sets or gets the value of the value attribute of an input button.
value |
Yes | Yes | Yes | Yes | Yes |
Return the value property.
var v = buttonObject.value
Set the value property.
buttonObject.value=text
Value | Description |
---|---|
text | The text displayed on the button |
A String type value representing the text displayed on the input button.
The following code shows how to get the text displayed on a button.
<!DOCTYPE html>
<html>
<body>
<input type="button" onclick="myFunction()" id="myBtn" value="test">
<p id="demo"></p>
<script>
function myFunction() {<!--from w ww . ja v a 2 s . com-->
var x = document.getElementById("myBtn").value;
document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>
The code above is rendered as follows:
The following code shows how to change the text displayed on a button.
<!DOCTYPE html>
<html>
<body>
<input type="button" id="myBtn" value="my button">
<button onclick="myFunction()">test</button>
<script>
function myFunction() {<!--from w w w .j av a2 s. co m-->
document.getElementById("myBtn").value = "a button";
}
</script>
</body>
</html>
The code above is rendered as follows: