Javascript Reference - HTML DOM Input Email placeholder Property








The placeholder attribute from the input email element displays a short hint text that describes the expected value of an email field.

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

Browser Support

placeholder Yes 10.0 Yes Yes Yes

Syntax

Return the placeholder property.

var v = emailObject.placeholder

Set the placeholder property.

emailObject.placeholder=text




Property Values

Value Description
text Set a short hint text that describes the expected value of the email field

Return Value

A String type value representing a short hint text that describes the expected value of the email field.

Example

The following code shows how to get the placeholder text of an email field.


<!DOCTYPE html>
<html>
<body>
<!--  w w w.j  av  a 2 s.  c om-->
Login: <input type="email" id="myEmail" placeholder="email@example.com">
<button onclick="myFunction()">test</button>

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

<script>
function myFunction() {
    var x = document.getElementById("myEmail").placeholder;
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

The code above is rendered as follows:





Example 2

The following code shows how to change the placeholder text of an email field.


<!DOCTYPE html>
<html>
<body>
<!--from  w w w.j  av  a  2  s.c om-->
E-mail: <input type="email" id="myEmail" placeholder="Email@example.com">
<button onclick="myFunction()">test</button>

<script>
function myFunction() {
    document.getElementById("myEmail").placeholder = "Your email address";
}
</script>

</body>
</html>

The code above is rendered as follows: