Find out if a text area automatically gets focus on page load:
var x = document.getElementById("myTextarea").autofocus;
Click the button to find out if the text area automatically gets focus on page load.
<!DOCTYPE html> <html> <body> Address:<br> <textarea id="myTextarea" autofocus> PO 1234, Main Street U.S.A. New York</textarea> <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() {/*w w w .ja va 2 s. c o m*/ var x = document.getElementById("myTextarea").autofocus; document.getElementById("demo").innerHTML = x; } </script> </body> </html>
The autofocus property sets or gets whether a text area should automatically get focus on page load.
This property mirrors the HTML autofocus attribute.
Value | Description |
---|---|
true | The text area gets focus |
false | Default. The text area does not get focus |
The autofocus property returns true if the text area automatically gets focus on page load, otherwise it returns false.