Textarea autofocus Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Textarea

Description

The autofocus property sets or gets whether a text area should get focus when the page loads, or not.

This property reflects the HTML autofocus attribute.

Set the autofocus property with the following Values

Value Description
true|false Sets whether a text area should get focus when the page loads

Return Value

A Boolean, returns true if the text area gets focus when the page loads, otherwise it returns false

The following code shows how to check if a text area gets focus upon page load:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>
Address:<br>
<textarea id="myTextarea" autofocus>
Main Street/*from   ww w. ja v a  2  s  .  com*/
New York</textarea>



<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {
    var x = document.getElementById("myTextarea").autofocus;
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

Related Tutorials