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