Javascript DOM HTML Input Email placeholder Property set

Introduction

Change the placeholder text of an email field:

document.getElementById("myEmail").placeholder = "Your Email address";

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

View in separate window

<!DOCTYPE html>
<html>
<body>

E-mail: <input type="email" id="myEmail" placeholder="Email adr">
<button onclick="myFunction()">Test</button>

<script>
function myFunction() {/*from ww  w  .j  av a 2 s.co  m*/
  document.getElementById("myEmail").placeholder = "Your email address";
}
</script>

</body>
</html>

The placeholder property sets or gets the value of the placeholder attribute of an email field.

The placeholder attribute stores a message hint for an email field.

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

The placeholder property accepts and returns a String type value.




PreviousNext

Related