Javascript examples for DOM HTML Element:Button
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 |
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:
<!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>