Open In App
Related Articles

jQuery :text Selector

Improve Article
Improve
Save Article
Save
Like Article
Like

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:

 


Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 17 Nov, 2022
Like Article
Save Article
Previous
Next
Similar Reads
Complete Tutorials