Javascript DOM HTML Input Button value Property get

Introduction

Get the text displayed on a button:

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

Click the input button to display the value of its value attribute.

View in separate window

<!DOCTYPE html>
<html>
<body>
<input type="button" onclick="myFunction()" id="myBtn" value="Test">

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

<script>
function myFunction() {/*from ww w.  jav a  2  s  .co m*/
  var x = document.getElementById("myBtn").value;
  document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>



PreviousNext

Related