Button value Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Button

Description

The value property sets or gets the value attribute of a button.

Set the value property with the following Values

Value Description
text The initial value of the button

Return Value

A String, representing the underlying value that is associated with the button

The following code shows how to return the value attribute of a button:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<button id="myBtn" name="myname" value="myvalue" onclick="console.log(this.value)">My Button</button>

<button onclick="myFunction()">Test</button>

<script>
function myFunction() {/*from   ww w. j av  a2s. c o m*/
    var v = document.getElementById("myBtn").value;
    console.log(v);
}
</script>

</body>
</html>

Related Tutorials