jQuery :password Selector (original) (raw)

Last Updated : 11 Jul, 2025

The jQuery :password Selector is used to select the input element having password field . i.e (type==password)

Syntax:

$(":password")

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

HTML `

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

GeeksForGeeks

jQuery :password Selector

Name:
Password:

        <input type="reset" value="Reset">
        <input type="submit" value="Submit">
        <br>
    </form>
  </center>

`

Output:

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

HTML `

<script>
    $(document).ready(function () {
        $("button").click(function () {
            $(":password").css("border",
                            "2px solid red");
        });
    });
</script>

GeeksForGeeks

jQuery :password Selector

Name:
Password:

        <input type="reset" value="Reset">
        <input type="submit" value="Submit">
        <br>
        <br>
        <button>Add border</button>
    </form>
</center>

`

Output: