Button value Property - Javascript DOM HTML Element

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

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>

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

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

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


Related Tutorials