Skip to content
Related Articles

Related Articles

jQuery :text Selector

Improve Article
Save Article
  • Last Updated : 17 Nov, 2022
Improve Article
Save 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
Related Articles

Start Your Coding Journey Now!