jQuery :text Selector

Beginner
7 min read
Updated: Oct 2026
5 examples
Live preview

What Is :text?

: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).

Remember
$("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")
NeedUse
All text inputs$("input:text")
Explicit type only$("input[type=\"text\"]")
Password fields$("input:password")
Textareas$("textarea") or $(":input")
Read values$("input:text").val()

How to Use :text

Prefix with input, scope to a form, then style, clear, or read values.

  1. Write $("input:text") — not bare $(":text").
  2. Scope to a form: $("#signup input:text").
  3. Remember typeless <input> elements count as text since 1.5.2.
  4. Do not expect textarea matches — select those separately.
  5. For native speed with explicit types only, use input[type="text"].
PieceRequired?Role
Selector stringYes:text (best with an input prefix)
Form contextOptionalLimits matches to one form
Return value—jQuery collection of matching text inputs

Pseudocode

Pseudocode
matches = []
for each input in search context:
    if type is "text"
       OR type attribute is missing (since 1.5.2):
        matches.add(input)

return matches

// [type=text] skips missing-type inputs

Cheat Sheet

Keep these facts handy while selecting text fields.

TopicDetail
Syntax$("input:text")
SincejQuery 1.0 · extension (typeless since 1.5.2)
Matchesinput with type text (or missing type)
Nottextarea, password, email, number, …
vs [type=text]Attribute form skips typeless inputs
vs .text()Method for text content — different API
PrefixAlways prefer input:text
Native CSSUse [type="text"] for speed

Live Preview

Run different selectors against a small sample form and compare :text with [type=text].

Sample includes typed text, typeless input, password, and textarea — mirrors the official form demo idea.

Result
$("form input:text")
matched: 2

/* typed + typeless text inputs */

jQuery Examples

Short, copy-ready snippets. Open DevTools Console with jQuery loaded, or use Try It Yourself for a live editor.

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.
  4. Safety. preventDefault() stops a real submit in the demo.

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.
  4. Choose. Use :text when typeless inputs must count.

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.
  4. Habit. Always write the tag for clarity and performance.

Example 4 — :text Does Not Match textarea

Multi-line fields are a different element — select them separately.

jQuery
console.log("input:text →", $("input:text").length);
console.log("textarea →", $("textarea").length);
console.log("password →", $("input:password").length);
Try It Yourself

How It Works

  1. Text inputs. :text is for single-line input fields.
  2. Textarea. Use the textarea tag selector.
  3. Password. Use :password — a different type.
  4. Broader set. :input can gather several control kinds at once.

Example 5 — Native Performance: input[type="text"]

Official tip — attribute selectors can use querySelectorAll.

jQuery
var $attr = $("input[type='text']");
var $pseudo = $("input:text");
$("#out").text(
  "[type=text]: " + $attr.length + "\\n" +
  "input:text: " + $pseudo.length + "\\n" +
  "(counts differ if typeless inputs exist)"
);
Try It Yourself

How It Works

  1. Native. [type="text"] is standard CSS.
  2. Faster. jQuery can hand it to querySelectorAll.
  3. Trade-off. You miss typeless inputs that :text includes.
  4. Rule. Need every text field including bare <input>? Keep :text.

Edge Cases & Pitfalls

Check these before relying on :text in real forms.

typeless

:text ≠ [type=text]

Since 1.5.2, typeless <input> matches :text only. Do not swap them blindly.

slow

Bare $(":text") scans widely

It implies *:text. Prefer $("input:text") or a form-scoped query.

textarea

Not a textarea selector

Multi-line fields need $("textarea"). :text never matches them.

name

Do not confuse with .text()

:text selects inputs. .text() reads/writes text content on any element.

Browser Support

The :text pseudo-class is a jQuery extension and has worked since jQuery 1.0 (typeless-input behavior since 1.5.2). Prefer input[type="text"] when you want native querySelectorAll performance.

✓ jQuery 1.0+ · extension

jQuery :text Selector

Supported across jQuery 1.x, 2.x, and 3.x. Prefer input:text; use [type="text"] for native speed when typeless inputs do not matter.

100% jQuery form selector
Google Chrome All versions · Desktop & Mobile
Full support
Mozilla Firefox All versions · Desktop & Mobile
Full support
Apple Safari All versions · macOS & iOS
Full support
Microsoft Edge All versions · Chromium & Legacy
Full support
Internet Explorer IE 6+ · Legacy environments
Full support
Opera All modern versions
Full support
:text Universal

Bottom line: Safe everywhere jQuery runs. Prefer input:text, remember the typeless-input difference, and scope to a form on large pages.

Performance Notes

ApproachCostBest for
$("input[type=\"text\"]")FastestExplicit type attributes / hot paths
$("form input:text")CheapTypical forms (includes typeless)
$("input:text")CheapPage-wide text fields
$(":text")SlowerAvoid — universal scan

Official docs: because :text is not CSS, it cannot use the querySelectorAll boost. Prefer [type="text"] when you only need explicit text inputs and performance matters.

Key Takeaways

  • Role: select single-line text input fields.
  • Prefix: use $("input:text"), not bare $(":text").
  • 1.5.2+: typeless <input> matches :text, not [type=text].
  • Not textarea: select textarea separately; next is :checked.

One line: $("input:text") finds text fields — including typeless inputs — and is not the same as [type=text] or .text().

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

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

:checked tutorial →

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