Javascript DOM HTML Input Button Object get

Introduction

The Input Button object represents an HTML <input> element with type="button".

We can access an <input> element with type="button" via document.getElementById():

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

Click the button to get the text displayed on the button.

View in separate window

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

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

</body>
</html>



PreviousNext

Related