- 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 Textarea autofocus Property
The HTML DOM Textarea autofocus property returns and modify whether the text area should automatically get focused or not when the page loads.
Syntax
Following is the syntax −
1. Returning autofocus
object.autofocus
2. Modifying autofocus
object.autofocus = true | false
Let us see an example of HTML DOM Textarea autofocus Property:
Example
<!DOCTYPE html> <html> <style> body { color: #000; height: 100vh; } .btn { background: #db133a; border: none; height: 2rem; border-radius: 2px; width: 40%; display: block; color: #fff; outline: none; cursor: pointer; } </style> <body> <h1>DOM Textarea autofocus Property Demo</h1> <textarea autofocus>Hi! I'm a text area element with some dummy text.</textarea> <button onclick="set()" class="btn">Disable Autofocus</button> <script> function set() { document.querySelector("textarea").autofocus = false; } </script> </body> </html>
Output
Click on “Disable Autofocus” button to disable autofocus on the textarea element. Now, the cursor won’t be visible:
Advertisements