Open In App

HTML DOM Input URL select() Method

The HTML <input type=”url”> is used to define a field that entered a URL. This input value is automatically validated before submitting the form.

The input URL select() method in HTML DOM is used to select the content of a URL text field. It is an in-built method of input URL Object. Refer to components of a URL from the given link



Approach: Blue background color is added to the content of the URL when the user clicks on the button to show that it’s selected.

Syntax:



URLObject.select()

Example: This example uses the input URL select() method to select the content inside the URL Field. 




<!DOCTYPE html>
<html>
 
<head>
    <title>    DOM Input URL select() Method </title>
</head>
 
<body>
    <center>
        <h1 style="color:green;">GeeksforGeeks</h1>
 
        <h2>DOM Input URL select() Method </h2>
 
        <label for="uname"    style="color:green">
            <b>Enter URL</b>
        </label>
 
        <input type="url" id="inputID"    placeholder="Enter URL"
               value="https://www.geeksforgeeks.org/">
        <br>
        <br>
 
        <button type="button" onclick="selectURLMethod()">
            Click
        </button>
 
        <script>
            function selectURLMethod() {
                document.getElementById("inputID").select();
            }
        </script>
    </center>
</body>
</html>

Output:

HTML DOM Input URL select() Method

Supported Browsers: The list of browsers supported by HTML DOM Input URL select() Method are listed below:- 


Article Tags :