Javascript DOM HTML Input Search placeholder Property set

Introduction

Change the placeholder text of a search field:

document.getElementById("mySearch").placeholder = "Search files";

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

View in separate window

<!DOCTYPE html>
<html>
<body>

<input type="search" id="mySearch" placeholder="Filter items">
<button onclick="myFunction()">Test</button>

<script>
function myFunction() {/*from  www  . ja  v a2 s  . c o  m*/
  document.getElementById("mySearch").placeholder = "Search files";
}
</script>

</body>
</html>

The placeholder property sets or gets the placeholder attribute of a search field.

The placeholder attribute sets a short message for a search field.

The short hint is displayed in the text field before the user enters a value.

The placeholder property accepts and returns a String type value




PreviousNext

Related