
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
HTML DOM Input Text Autofocus Property
The HTML DOM input Text autofocus property is associated with the HTML <input> element’s autofocus attribute. This property is used for setting or returning if the input text field should be automatically focused when the page loads or not.
Syntax
Following is the syntax for −
Setting the autofocus property −
textObject.autofocus = true|false
Here, true represents the text field should get focus and false represents otherwise. It is set to false by default.
Example
Let us look at an example for the HTML DOM Input text autofocus property −
<!DOCTYPE html> <html> <body> <h1>Input text autofocus property</h1> USERNAME: <input type="text" id="TEXT1" autofocus> <br><br> <button onclick="FocusVal()">CHECK FOCUS</button> <p id="Sample"></p> <script> function FocusVal() { var P = document.getElementById("TEXT1").autofocus; document.getElementById("Sample").innerHTML = "The text field has autofocus property set to "+P; } </script> </body> </html>
Output
This will produce the following output −
Advertisements