jQuery :password Selector

Beginner
5 min read
Updated: Nov 2026
3 examples
Selectors

Definition

:password selects every element of type password — usually <input type="password">. Official docs: equivalent to $("[type=password]"). Available since jQuery 1.0.

Syntax

Start with these common calls. Keep them short and readable.

jQuery
$("input:password")           → recommended
$("[type=password]")          → equivalent (official)
$("input[type='password']")   → best for modern browsers

$(":password")                → means *:password (avoid)

<input type="password">  → matches
<input type="text">      → no match
CallWhat it does
input prefixAvoids universal *:password scan
:passwordKeeps type=password controls
Form contextLimits matches to one form

Load jQuery before your script (CDN or local file), then wrap DOM work in $(function () { ... }) when needed.

Parameters

ParameterDescription
Step 1Write input:password (not bare :password).
Step 2Scope to a form when the page has many fields: $("#login input:password").
Step 3For speed in modern browsers, use input[type="password"].

Return Value

Return ValueDescription
See examplesCheck the examples below for what this API returns in common cases.

jQuery Examples

Example 1 — Official Demo: input:password

Count password inputs in a mixed form (jQuery API example idea).

jQuery
var $input = $("input:password");
console.log("For this type jQuery found " + $input.length + ".");
console.log("names:", $input.map(function () {
  return this.name || "(no name)";
}).get().join(", "));
Try It Yourself

How It Works

  1. Match password inputs. input:password keeps type=password only.
  2. Ignore other controls. Text, checkbox, select, and button are skipped.
  3. Report the count. Official demo prints how many were found.

Example 2 — Same as [type=password]

Official docs: the pseudo-class and attribute selector return the same set.

jQuery
var $a = $("input:password");
var $b = $("[type=password]");
var $c = $("input[type='password']");

console.log(":password →", $a.length);
console.log("[type=password] →", $b.length);
console.log("input[type=...] →", $c.length);
console.log("same size:", $a.length === $b.length && $b.length === $c.length);
Try It Yourself

How It Works

  1. Three spellings. All target type=password.
  2. Same length. Matched sets agree.
  3. Attribute form is CSS. Best for native performance.

Example 3 — Prefer input:password

Bare :password implies the universal selector — prefix with input.

jQuery
console.log("input:password →", $("input:password").length);
console.log(":password →", $(":password").length);
console.log("same here:", $("input:password").length === $(":password").length);
Try It Yourself

How It Works

  1. Typed form. Official recommendation: precede with a tag.
  2. Bare form. Means *:password — wider scan.
  3. Same on tiny demos. Counts often match by coincidence.

Frequently Asked Questions

:password selects every element of type password — typically <input type="password">. $("input:password") finds all password fields in scope. Available since jQuery 1.0.
Yes. Official docs: $( ":password" ) is equivalent to $( "[type=password]" ). For native querySelectorAll speed, prefer input[type="password"].
Prefer $("input:password"). Bare $(':password') implies the universal selector ($('*:password')). Official docs recommend preceding it with a tag name.
No. It is a jQuery extension. Native querySelectorAll cannot run :password. Use input[type="password"] for standard CSS matching.
:password matches masked password inputs. :text matches plain text inputs. They never overlap.
It styles $("input:password") and reports how many were found in a sample form that also includes text, textarea, checkbox, radio, select, and button controls.

Next: :image Selector — Select Image Inputs

Select image-type inputs used as graphical submit buttons.

:image Selector — Select Image Inputs tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

11 people found this page helpful