Javascript examples for DOM HTML Element:Input Search
The placeholder property sets or gets the value of the placeholder attribute of a search field.
Set the placeholder property with the following Values
Value | Description |
---|---|
text | Sets a short hint that describes the expected value of the search field |
A String, representing a short hint that describes the expected value of the search field
The following code shows how to change the placeholder text of a search field:
<!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 .j a v a 2 s. c o m*/ var x = document.getElementById("mySearch").placeholder; document.getElementById("demo").innerHTML = x; } </script> </body> </html>