Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App
geeksforgeeks
Browser
Continue

Related Articles

jQuery :text Selector

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

The jQuery :text Selector is used to select input element with having a text field i.e (type==text). 

Syntax: 

$(":text") 

Example 1: In this example, we will select the input element that has a text field by using jQuery :text Selector.

HTML




<!DOCTYPE html>
<html>
   
<head>
    <script src=
    </script>
   
    <script>
        $(document).ready(function () {
            $(":text").css("background-color",
                "green");
        });
    </script>
</head>
   
<body>
    <center>
        <h1 style="color:green;">
            GeeksForGeeks
        </h1>
        <h2>jQuery :text Selector</h2>
        <form action="">
            Name:
            <input type="text" name="user">
            <br>
              Password:
            <input type="password" name="password">
            <br>
            <br>
            <input type="reset" value="Reset">
            <input type="submit" value="Submit">
            <br>
        </form>
    </center>
</body>
   
</html>

Output:

  

Example 2: In this example, we will change the background color of the input element that has a text field with the help of click function.

HTML




<!DOCTYPE html>
<html>
   
<head>
    <script src=
    </script>
   
    <script>
        $(document).ready(function () {
            $("button").click(function () {
                $(":text").css("background-color",
                                "yellow");
            });
        });
    </script>
</head>
   
<body>
    <center>
        <h1 style="color:green;">
            GeeksForGeeks
        </h1>
        <h2>jQuery :text Selector</h2>
        <form action="">
            Name:
            <input style="background-color: aqua;"
                type="text" name="user">
            <br>
              Password:
            <input style="background-color: blueviolet;"
                type="password" name="password">
            <br>
            <br>
            <input type="reset" value="Reset">
            <input type="submit" value="Submit">
            <br>
            <button>change color</button>
        </form>
    </center>
</body>
   
</html>

Output:

 


My Personal Notes arrow_drop_up
Last Updated : 17 Nov, 2022
Like Article
Save Article
Similar Reads
Related Tutorials