Open In App

HTML DOM Input Search select() Method

The Input Search select() Method in HTML DOM is used to select the content of the Input search text field. It is the predefined method of the Search object. 

Syntax:



searchObject.select()

Example: This example uses the Input Search select() method to select the content inside the search field.   




<!DOCTYPE html>
<html>
 
<head>
    <style>
        h1 {
            color: green;
        }
 
        body {
            text-align: center;
        }
    </style>
</head>
 
<body>
    <h1>GeeksforGeeks</h1>
    <h2>Input Search select() Method</h2>
 
    <input type="Search" id="test"
           placeholder="Type to search.."
           value="GeeksForGeeks">
    <br>
    <br>
    <br>
    <button onclick="selectContent()">
      Select the Content of Search Field
    </button>
 
    <script>
        function selectContent() {
           
            // Use the select() method
            document.getElementById(
                "test"
            ).select();
        }
    </script>
</body>
 
</html>

Output:



Supported Browsers:


Article Tags :