Javascript DOM HTML Button value Property get

Introduction

Return the value attribute of a button:

var x = document.getElementById("myBtn").value;

Click the button to return the value of its value attribute.

View in separate window

<!DOCTYPE html>
<html>
<body>

<button id="myBtn" value="myvalue" onclick="myFunction()">Test</button>

<p id="demo"></p>

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

</body>
</html>

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

The value attribute sets the underlying value that is associated with a button.




PreviousNext

Related