Javascript DOM HTML Input Search placeholder Property get

Introduction

Get the placeholder text of a search field:

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

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

View in separate window

<!DOCTYPE html>
<html>
<body>

<input type="search" id="mySearch" placeholder="Search for something..">
<button onclick="myFunction()">Test</button>

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

<script>
function myFunction() {/*from w  ww.  ja v  a  2s  .  c o m*/
  var x = document.getElementById("mySearch").placeholder;
  document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>



PreviousNext

Related