Input Button autofocus Attribute

Definition and Usage

autofocus Sets or returns whether the input button 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 button automatically gains focus when the page is loaded:

var x = document.getElementById("myBtn").autofocus;

Try it yourself

Syntax

Return the autofocus attribute:

buttonObject.autofocus

Set the autofocus attribute:

buttonObject.autofocus = true|false

Attribute value

Value Description
true|false

Specifies whether the input button should gain focus when the page is loaded.

  • true - The input button gains focus
  • false - Default. The input button does not gain focus

Technical Details

Return Value: Boolean value, returned if the input button automatically gains focus when the page is loaded true, otherwise return false.

Browser Support

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
Support Support Support Support Support