Javascript DOM HTML Input URL placeholder Property set

Introduction

Change the placeholder text of a URL field:

document.getElementById("myURL").placeholder = "Type URL here..";

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

elements with type="url" are not supported in Safari.

View in separate window

<!DOCTYPE html>
<html>
<body>

Homepage: <input type="url" id="myURL" placeholder="URL">
<button onclick="myFunction()">Test</button>

<script>
function myFunction() {// w w w  .ja  va2 s . c  om
  document.getElementById("myURL").placeholder = "Type URL here..";
}
</script>

</body>
</html>

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

The placeholder attribute sets a short hint message for an URL field.

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

This property mirrors the HTML placeholder attribute.

The placeholder property accepts and returns a String type value.




PreviousNext

Related