jQuery :text Selector

Beginner
5 min read
Updated: Nov 2026
3 examples
Selectors

Definition

:text (since jQuery 1.0) selects <input> elements of type text. Prefer $("input:text") over bare $(":text"). Since 1.5.2, it also matches inputs with no type attribute (text is implied).

Syntax

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

jQuery
$("input:text")              // recommended
$("form input:text")         // official demo style
$("input[type=text]")        // explicit attribute only

$(":text")                   // avoid — implies *:text

// Since 1.5.2:
$("<input>").is(":text")        // true  (no type → text)
$("<input>").is("[type=text]")  // false

// Not textarea — use $("textarea")
CallWhat it does
Selector string:text (best with an input prefix)
Form contextLimits matches to one form
Return valuejQuery collection of matching text inputs

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

Parameters

ParameterDescription
Step 1Write $("input:text") — not bare $(":text").
Step 2Scope to a form: $("#signup input:text").
Step 3Remember typeless <input> elements count as text since 1.5.2.

Return Value

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

jQuery Examples

Example 1 — Official Demo: form input:text

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

jQuery
var input = $("form input:text");
$("#count").text("For this type jQuery found " + input.length + ".");
$("form").on("submit", function (e) { e.preventDefault(); });
Try It Yourself

How It Works

  1. Scope. form input:text searches text inputs inside the form.
  2. Filter. Password and submit controls are ignored.
  3. Count. .length is how many text inputs matched.

Example 2 — Official Difference: :text vs [type=text]

Since 1.5.2, typeless <input> matches :text but not [type=text].

jQuery
console.log("input:text →", $("input:text").length);
console.log("[type=text] →", $("input[type=text]").length);
console.log("typeless is :text?", $("input").eq(1).is(":text"));
console.log("typeless is [type=text]?", $("input").eq(1).is("[type=text]"));
Try It Yourself

How It Works

  1. :text. Includes typed and typeless text inputs.
  2. Attribute. [type=text] needs the attribute written in HTML.
  3. .is(). Official docs show this exact true/false contrast.

Example 3 — Prefer input:text Over Bare :text

Official tip — prefix pseudo-classes so you do not imply *:text.

jQuery
console.log("input:text →", $("input:text").length);
console.log(":text →", $(":text").length);
// Same matches here, but input:text is clearer and safer on large pages
Try It Yourself

How It Works

  1. Prefix. input:text starts from input elements only.
  2. Bare. :text implies a universal scan first.
  3. Same small demo. Counts may match on tiny pages.

Frequently Asked Questions

:text selects every input element of type text — single-line text fields. Prefer $("input:text"). Available since jQuery 1.0.
Prefer $("input:text"). Bare $(':text') implies $('*:text') and scans more of the page. Official docs recommend prefixing with input.
Since jQuery 1.5.2, :text also matches <input> with no type attribute (type=text is implied). [type=text] matches only when the attribute is present. Official demo: $("<input>").is(":text") is true; .is("[type=text]") is false.
No. It selects input elements of type text only. Use $("textarea") or :input for textareas.
No. :text is a selector for text inputs. .text() gets or sets text content on elements. Same name, different jobs.
No. It is a jQuery extension, so it cannot use querySelectorAll. Prefer [type="text"] for speed when you only need explicit type=text attributes.

Next: :checked Selector — Checkboxes, Radios & Options

Learn how to match checked checkboxes, radios, and options with :checked.

:checked Selector — Checkboxes, Radios & Options 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.

9 people found this page helpful