HTML DOM Input Search focus() Method
Last Updated :
30 Aug, 2022
The Input Search focus() Method in HTML DOM is used to get focus to the Input search Field when an event occurs.
Syntax:
searchObject.focus();
Parameter: This method does not contain any parameter value.
Return Value: It does not return any value.
Example: The below example illustrates the use of the Input search focus() method in HTML DOM.
HTML
<!DOCTYPE html>
< html >
< head >
< title > Input Search Focus() Method </ title >
< style >
h1 {
color: green;
}
h2 {
font-family: Impact;
}
body {
text-align: center;
}
</ style >
</ head >
< body >
< h1 >GeeksforGeeks</ h1 >
< h3 >Input Search Focus() Method</ h3 >
< form id = "myGeeks" >
< input type = "Search"
id = "test"
name = "myGeeks"
placeholder = "Type to search.."
value = "GeeksforGeeks" autofocus>
</ form >
< br >< br >
< button onclick = "Focus()" > Get Focus </ button >
< script >
function Focus() {
var s = document.getElementById("test").focus();
}
</ script >
</ body >
</ html >
|
Output:
Input Search focus() Method
Supported Browser:
- Google Chrome 5 and above
- Opera 10.6 and above
- Microsoft Edge 12.0 and above
- Safari 5 and above
- Firefox 4 and above
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...