jQuery :password Selector

The jQuery :password selector select all the input type password elements in a form. This can be useful when you want to apply CSS only to the password input field.

A login form contains username and password fields. Both are the input elements of the form. However, the selector selects only the password input element and not the username.

jQuery :password Selector

Syntax of the Selector

The syntax of jQuery :password selector is given below.

Syntax
$(“:password”)

The above syntax showing that it requires no parameters to pass. If you want to select only the specified input item, you have to use the class name or id of the element.

jQuery :password Selector Select All Input Type Password Elements

When you want to create a login form, you have to add a password input element to get the password as user input. The selector selects only the element with the input type="password" attribute. After you select the required element, you can apply CSS and other effects with jQuery.

See the example given below to use it.

Example

Test it Live

Output




The above example showing the two input elements. One is for username and the other is for the password. The selector selects the input password field and applies the background color to it. It applies the ‘yellow’ background color to highlight the form elements.

If you have any queries regarding this tutorial post, please comment below.

Also tell me, what other methods you are using with the selector by commenting below.

References