X
HOME HTML CSS JAVASCRIPT SQL PHP JQUERY XML ASP.NET MORE...
REFERENCES | EXAMPLES | FORUM | ABOUT

Button autofocus Property

Button Object Reference Button Object

Example

Find out if a button automatically gets focus upon page load:

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

The result of x will be:

true

Try it yourself »


Definition and Usage

The autofocus property sets or returns whether a button should automatically get focus when the page loads, or not.

This property reflects the HTML autofocus attribute.

Note: The autofocus attribute is new for the <button> element in HTML5.


Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

The autofocus property is supported in all major browsers.

Note: The autofocus property is not supported in Internet Explorer 9 and earlier versions or in Opera 12 and earlier versions.


Syntax

Return the autofocus property:

buttonObject.autofocus

Set the autofocus property:

buttonObject.autofocus=true|false

Property Values

Value Description
true|false Specifies whether a button should get focus when the page loads, or not
  • true - The button gets focus
  • false - Default. The button does not get focus

Technical Details

Return Value: A Boolean, returns true if the button automatically gets focus when the page loads, otherwise it returns false


Related Pages

HTML reference: HTML <button> autofocus attribute


Button Object Reference Button Object

Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]
Search w3schools.com:

WEB BUILDING

Download XML Editor FREE Website BUILDER Free HTML5 Templates FREE Website Templates Free HTML Templates

SHARE THIS PAGE

facebook