- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- 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 Number autofocus Property
The HTML DOM input number autofocus property returns and modify whether the input number field should get focused or not when page load.
Syntax
Following is the syntax −
Returning autofocus
object.autofocus
2. Modifying autofocus
object.autofocus = true | false
Example
Let us see an example of HTML DOM input number autofocus property −
<!DOCTYPE html> <html> <head> <title>HTML DOM autofocus property</title> <style> body{ text-align:center; background-color:#1b203a; color:#ff8741; } p{ font-size:1.2rem; } input{ border:none; background-color:#ffffff4a; height:1.2rem; padding:8px; color:#fff; font-weight:bold; font-size:1rem; } button{ background-color:#db133a; color:#fff; padding:8px; border:none; width:120px; margin:0.5rem; border-radius:50px; outline:none; cursor:pointer; } </style> </head> <body> <h1>autofocus Property Example</h1> <p>Hi! click on disable button to disable autofocus</p> <input type="number" autofocus value="23450004"> <br> <button onclick="disable()">Disable</button> <script> function disable() { document.querySelector("input").autofocus = false; } </script> </body> </html>
Output
This will produce the following output −
Click on “Disable” button to disable the autofocus on month input field.
Advertisements