The autofocus
property sets or gets whether
an email field can automatically get focus when the page loads.
autofocus |
Yes | Yes | Yes | Yes | Yes |
Return the autofocus property.
var v = emailObject.autofocus
Set the autofocus property.
emailObject.autofocus=true|false
Value | Description |
---|---|
true|false | Specifies whether an email field should get focus when the page loads
|
A Boolean type value, true if the email field automatically gets focus when the page loads, otherwise false.
The following code shows how to get if an email field automatically can get focus upon page load.
<!DOCTYPE html>
<html>
<body>
<!-- ww w.j a va 2s.co m-->
E-mail: <input type="email" id="myEmail" autofocus>
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<script>
function myFunction() {
var x = document.getElementById("myEmail").autofocus;
document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>
The code above is rendered as follows: