The autofocus
property sets or gets
whether a checkbox can automatically get focus when the page loads.
autofocus |
Yes | 10.0 | Yes | Yes | Yes |
Return the autofocus property.
var v = checkboxObject.autofocus
Set the autofocus property.
checkboxObject.autofocus=true|false
Value | Description |
---|---|
true|false | Specifies whether a checkbox can get focus when the page loads
|
A Boolean type value, true if the checkbox can automatically get focus when the page loads, otherwise it returns false.
The following code shows how to get if a checkbox automatically can get focus upon page load.
<!DOCTYPE html>
<html>
<body>
Checkbox: <input type="checkbox" id="myCheck" autofocus>
<p id="demo"></p>
<button onclick="myFunction()">test</button>
<script>
function myFunction() {<!--from ww w. ja v a2 s .com-->
var x = document.getElementById("myCheck").autofocus;
document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>
The code above is rendered as follows: