Horje
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>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



Reffered: https://www.geeksforgeeks.org


HTML

Related
HTML DOM Input Text focus() Method HTML DOM Input Text focus() Method
What are Cell Padding &amp; Cell Spacing in HTML Table ? What are Cell Padding &amp; Cell Spacing in HTML Table ?
What is the significance of adding autocomplete attribute in HTML Form ? What is the significance of adding autocomplete attribute in HTML Form ?
HTML DOM Textarea type Property HTML DOM Textarea type Property
HTML nonce Attribute HTML nonce Attribute

Type:
Geek
Category:
Coding
Sub Category:
Tutorial
Uploaded by:
Admin
Views:
12