Input Submit autofocus Attribute

Definition and Usage

autofocus Attribute sets or returns whether the submit button should automatically obtain focus when the page is loaded.

This attribute reflects the HTML autofocus attribute.

See Also:

HTML Reference Manual:HTML <input> autofocus Attribute

Example

Find out if the submit button automatically obtains focus when the page is loaded:

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

Try It Yourself

Syntax

Return autofocus attribute:

submitObject.autofocus

Set autofocus attribute:

submitObject.autofocus = true|false

Attribute Value

Value Description
true|false

Define whether the submit button should obtain focus when the page is loaded.

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

Technical Details

Return Value: Boolean value, returned if the submit button 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