jQuery :text Selector (original) (raw)

Last Updated : 11 Jul, 2025

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 `

<script>
    $(document).ready(function () {
        $(":text").css("background-color",
            "green");
    });
</script>

GeeksForGeeks

jQuery :text Selector

Name:
Password:


`

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 `

<script>
    $(document).ready(function () {
        $("button").click(function () {
            $(":text").css("background-color",
                            "yellow");
        });
    });
</script>

GeeksForGeeks

jQuery :text Selector

Name:
Password:


change color

`

Output: