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.
placeholder |
Yes | 10.0 | Yes | Yes | Yes |
Return the placeholder property.
var v = emailObject.placeholder
Set the placeholder property.
emailObject.placeholder=text
Value | Description |
---|---|
text | Set a short hint text that describes the expected value of the email field |
A String type value representing a short hint text that describes the expected value of the email field.
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:
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: