YouTip LogoYouTip

Prop Search Autofocus

HTML DOM Input Search autofocus Property

HTML DOM Input Search autofocus Property

-- Learning is not just about technology, but also about dreams!

JavaScript Reference

Overview

JavaScript Objects

JavaScript Array Object JavaScript Boolean Object JavaScript Date Object JavaScript Math Object JavaScript Number Object JavaScript String Object JavaScript RegExp Object JavaScript Global Properties/Functions JavaScript Operators JavaScript Error

Browser Objects

Window Object Navigator Object Screen Object History Object Location Object Storage Object

DOM Objects

HTML DOM Document Object HTML DOM Element Object HTML DOM Attribute Object HTML DOM Event Object HTML DOM Console Object CSSStyleDeclaration Object DOM HTMLCollection

HTML Objects

<a> <area> <audio> <base> <blockquote> <body> <button> <canvas> <col> <colgroup> <datalist> <del> <details> <dialog> <embed> <fieldset> <form> <iframe> <frameset> <img> <ins> <input> - button <input> - checkbox <input> - color <input> - date <input> - datetime <input> - datetime-local <input> - email <input> - file <input> - hidden <input> - image <input> - month <input> - number <input> - range <input> - password <input> - radio <input> - reset <input> - search <input> - submit <input> - text <input> - time <input> - url <input> - week <keygen> <link> <label> <legend> <li> <map> <menu> <menuItem> <meta> <meter> <object> <ol> <optgroup> <option> <param> <progress> <q> <script> <select> <source> <style> <table> <td> <th> <tr> <textarea> <title> <time> <track> <video>

HTML DOM Reset Object

HTML DOM Submit Object

Input Search autofocus Property

Input Search Object Reference Input Search Object

Example

Check if the search field automatically gets focus after the page loads:

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

x output result:

true

Try it yourself Β»


Definition and Usage

The autofocus property sets or returns whether a search field should automatically get focus when the page loads.

This property reflects the HTML autofocus attribute.


Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

The autofocus property is supported by all major browsers.

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


Syntax

Return the autofocus property:

searchObject.autofocus

Set the autofocus property:

searchObject.autofocus=true|false

Property Values

Value Description
true|false Specifies whether the search field should get focus after the page loads.
* true - The search field gets focus.
* false - Default. The search field does not get focus.

Technical Details

Return Value: A Boolean. Returns true if the search field automatically gets focus after the page loads, otherwise false.

Related Pages

HTML Reference: HTML <input> autofocus Attribute


Input Search Object Reference Input Search Object

HTML DOM Reset Object

HTML DOM Submit Object

← Prop Search DisabledProp Search Autofocus β†’