
- HTML Tutorial
- HTML - Home
- HTML - Overview
- HTML - Basic Tags
- HTML - Elements
- HTML - Attributes
- HTML - Formatting
- HTML - Phrase Tags
- HTML - Meta Tags
- HTML - Comments
- HTML - Images
- HTML - Tables
- HTML - Lists
- HTML - Text Links
- HTML - Image Links
- HTML - Email Links
- HTML - Frames
- HTML - Iframes
- HTML - Blocks
- HTML - Backgrounds
- HTML - Colors
- HTML - Fonts
- HTML - Forms
- HTML - Embed Multimedia
- HTML - Marquees
- HTML - Header
- HTML - Style Sheet
- HTML - Javascript
- HTML - Layouts
- HTML References
- HTML - Tags Reference
- HTML - Attributes Reference
- HTML - Events Reference
- HTML - Fonts Reference
- HTML - ASCII Codes
- ASCII Table Lookup
- HTML - Color Names
- HTML - Entities
- HTML - Fonts Ref
- HTML - Events Ref
- MIME Media Types
- HTML - URL Encoding
- Language ISO Codes
- HTML - Character Encodings
- HTML - Deprecated Tags
HTML DOM Select autofocus Property
The HTML DOM select autofocus property returns and modify whether the drop-down list should get focused or not when page load.
Syntax
Following is the syntax −
1. Returning autofocus
object.autofocus
Modifying autofocus
object.autofocus = true | false
Example
Let us see an example of HTML DOM select autofocus property −
<!DOCTYPE html> <html> <head> <title>HTML DOM autofocus property</title> <style> body{ text-align:center; color:#fff; background: radial-gradient( circle farthest-corner at 23.1% 64.6%, rgba(129,125,254,1) 0%, rgba(111,167,254,1) 90% ) no-repeat; height:100vh; } p{ font-weight:700; font-size:1.1rem; } .drop-down{ display:block; width:35%; border:none; font-weight:bold; padding:10px; margin:1rem auto; background-color:#ffffff7a; outline-color:black; } .btn{ background:orange; border:none; height:2rem; border-radius:2px; width:35%; margin:2rem auto; display:block; color:#fff; font-weight:bold; outline:none; cursor:pointer; } </style> </head> <body> <h1>autofocus Property Example</h1> <p>Hi, Select your favourite subject:</p> <select class='drop-down' name="Drop Down List"> <option>Physics</option> <option>Maths</option> <option>Chemistry</option> <option>English</option> <option>Economics</option> <option>Hindi</option> <option>Biology</option> </select> <br> <button onclick="disable()" class="btn">Disable Autofocus</button> <script> function disable() { document.querySelector(".drop-down").autofocus = false; } </script> </body> </html>
Output
This will produce the following output −
Click on “Disable Autofocus” button to disable autofocus on drop-down list.
- Related Articles
- HTML DOM Button autofocus Property
- HTML DOM Textarea autofocus Property
- HTML DOM Input URL autofocus Property
- HTML DOM Input Week autofocus Property
- HTML DOM Input Password autofocus Property
- HTML DOM Input Search autofocus Property
- HTML DOM Input Submit autofocus property
- HTML DOM Input Text autofocus Property
- HTML DOM Input Radio autofocus property
- HTML DOM Input Range autofocus property
- HTML DOM Input Reset autofocus property
- HTML DOM Input Checkbox autofocus Property
- HTML DOM Input Month autofocus Property
- HTML DOM Input Number autofocus Property
- HTML DOM Input Color autofocus Property

Advertisements