HTML DOM Input Search focus() Method
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 >w3wiki</ h1 > < h3 >Input Search Focus() Method</ h3 > < form id = "myBeginner" > < input type = "Search" id = "test" name = "myBeginner" placeholder = "Type to search.." value = "w3wiki" autofocus> </ form > < br >< br > < button onclick = "Focus()" > Get Focus </ button > < script > function Focus() { var s = document.getElementById("test").focus(); } </ script > </ body > </ html > |
Output:
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