The autofocus
property,
new for the <button> element in HTML5,
sets or gets whether a button should automatically get focus.
autofocus |
Yes | 10 | Yes | Yes | Yes |
Return the autofocus property:
var v = buttonObject.autofocus
Set the autofocus property:
buttonObject.autofocus=true|false
Value | Description |
---|---|
true|false | whether to auto focus a button. Default to false. |
A Boolean value, true if the button automatically gets focus, otherwise false.
The following code shows how to find out if a button can automatically get focus.
<!DOCTYPE html>
<html>
<body>
<button id="myBtn" autofocus>My Button</button>
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<script>
function myFunction() {<!-- ww w. j a va2s . c o m-->
var x = document.getElementById("myBtn").autofocus;
document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>
The code above is rendered as follows: