Input Checkbox autofocus Attribute

Definition and Usage

autofocus The attribute sets or returns whether the checkbox should automatically gain focus when the page loads.

This property reflects the HTML autofocus attribute.

See also:

HTML Reference Manual:HTML <input> autofocus Attribute

Example

Find out if the checkbox automatically gains focus when the page loads:

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

Try it yourself

Syntax

Return the autofocus attribute:

checkboxObject.autofocus

Set the autofocus attribute:

checkboxObject.autofocus = true|false

Attribute value

Value Description
true|false

Specifies whether the checkbox should gain focus when the page loads

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

Technical Details

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