Javascript examples for DOM HTML Element:Input Button
The autofocus property sets or gets whether an input button should get focus when the page loads.
This property reflects the HTML autofocus attribute.
Set the autofocus property with the following Values
Value | Description |
---|---|
true|false | Sets whether an input button should get focus when the page loads |
A Boolean, returns true if the input button gets focus when the page loads, otherwise false
The following code shows how to check if a button automatically gets focus upon page load:
<!DOCTYPE html> <html> <body> <input type="button" id="myBtn" autofocus value="Input Button"> <p>Click the button below to find out if the input button above automatically gets focus when the page loads.</p> <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() {//from w w w. j av a2s .c om var x = document.getElementById("myBtn").autofocus; document.getElementById("demo").innerHTML = x; } </script> </body> </html>