The autofocus
property sets or gets whether a textarea can auto focus when the page loads.
autofocus |
Yes | 10.0 | Yes | Yes | Yes |
Return the autofocus property.
var v = textareaObject.autofocus
Set the autofocus property.
textareaObject.autofocus=true|false
Value | Description |
---|---|
true|false | Set whether a textarea can auto focus when the page loads
|
A Boolean type value, true if the textarea can auto focus when the page loads, otherwise false.
The following code shows how to check if a textarea can auto focus upon page load.
<!DOCTYPE html>
<html>
<body>
<textarea id="myTextarea" autofocus>
</textarea>
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<!--from w w w. j ava 2s . c o m-->
<script>
function myFunction() {
var x = document.getElementById("myTextarea").autofocus;
document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>
The code above is rendered as follows: