Button autofocus attribute
Definition and usage
autofocus
whether the button automatically gets focus when the page is loaded.
This attribute reflects HTML autofocus attribute.
Note:autofocus attribute It is a new attribute of the <button> element in HTML5.
Example
Check if the button automatically gets focus when the page is loaded:
var x = document.getElementById("myBtn").autofocus;
Syntax
Return the autofocus attribute:
buttonObject.autofocus
Set the autofocus attribute:
buttonObject.autofocus = true|false
attribute value
value | description |
---|---|
true|false |
Specifies whether the button receives focus when the page loads.
|
Technical Details
Return Value: | Boolean value, returns true if the button automatically focuses when the page loads, otherwise returns false. |
---|
Browser Support
Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|
Chrome | Edge | Firefox | Safari | Opera |
Support | 10.0 | Support | Support | Support |
Related Pages
HTML Reference Manual:HTML <button> autofocus Attribute