Input Text autofocus Attribute
Definition and Usage
autofocus
Attribute sets or returns whether the text field should automatically gain focus when the page is loaded.
This property reflects the HTML autofocus attribute.
See Also:
HTML Reference Manual:HTML <input> autofocus Attribute
Example
Check if the text field automatically gains focus when the page is loaded:
var x = document.getElementById("myPassword").autofocus;
Syntax
Return the autofocus attribute:
textObject.autofocus
Set the autofocus attribute:
textObject.autofocus = true|false
Attribute Value
Value | Description |
---|---|
true|false |
Specify whether the text field should gain focus when the page is loaded.
|
Technical Details
Return Value: | Boolean value, returned if the text field automatically gains focus when the page is loaded true ; otherwise return false . |
---|
Browser Support
The numbers in the table indicate the first browser version that fully supports this attribute.
Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|
Chrome | Edge | Firefox | Safari | Opera |
Support | 10.0 | Support | Support | Support |