Javascript DOM HTML Input Number placeholder Property get

Introduction

Display the placeholder text of a number field:

var x = document.getElementById("myNumber").placeholder;

Click the button to display the placeholder text of the number field.

View in separate window

<!DOCTYPE html>
<html>
<body>

<input type="number" id="myNumber" placeholder="Favorite Number">
<button onclick="myFunction()">Test</button>
<p id="demo"></p>

<script>
function myFunction() {// w  ww. j a  v a 2s  .  co  m
  var x = document.getElementById("myNumber").placeholder;
  document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>



PreviousNext

Related