HTML DOM Input Button autofocus Property
Last Updated :
02 Jan, 2024
The Input Button autofocus Property in HTML DOM is used to set or return whether the Input Button field should automatically get focused or not when the page loads. This Property is used to reflect the HTML autofocus attribute.Â
Syntax:Â
- It returns the autofocus property.
buttonObject.autofocus
- It is used to set the autofocus property.
buttonObject.autofocus = true|false
Property Values:Â
- true: It specify that the Button field get focus.
- false: It specify that the Button field does not get focus. It has a default value.
Return Value: It returns a Boolean value which represents that the Button field get focus or not when the page loads.Â
Example 1: This Example illustrates how to return the autofocus Property.Â
HTML
<!DOCTYPE html>
< html >
< head >
< title >
HTML DOM Input Button autofocus Property
</ title >
</ head >
< body style = "text-align:center;" >
< h1 >GeeksforGeeks</ h1 >
< h2 >HTML DOM Input Button autofocus Property</ h2 >
< form id = "myGeeks" >
< input type = "button" id = "GFG"
onclick = "myGeeks()" name = "Geek_button"
value = "Submit" autofocus>
</ form >
< p id = "result" ></ p >
< script >
function myGeeks() {
// Return Input Button autofocus Property
let btnFocus = document.getElementById("GFG").autofocus;
document.getElementById("result").innerHTML = btnFocus;
}
</ script >
</ body >
</ html >
|
Output:Â
Example 2: This example illustrates how to set the autofocus Property.Â
HTML
<!DOCTYPE html>
< html >
< head >
< title >
HTML DOM Input Button autofocus Property
</ title >
</ head >
< body style = "text-align:center;" >
< h1 >GeeksforGeeks</ h1 >
< h2 >HTML DOM Input Button autofocus Property</ h2 >
< form id = "myGeeks" >
< input type = "button" id = "GFG"
onclick = "myGeeks()" name = "Geek_button"
value = "Submit" autofocus>
</ form >
< p id = "result" ></ p >
< script >
function myGeeks() {
// Setting Input Button autofocus Property
let btnFocus = document.getElementById("GFG")
.autofocus = false;
document.getElementById("result").innerHTML
= btnFocus;
}
</ script >
</ body >
</ html >
|
Output:
Supported Browsers:
- Google Chrome
- Internet Explorer 10.0 +
- Firefox
- Opera
- Safari
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...