jQuery :text Selector

Beginner
⏱️ 8 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Text inputs

What You’ll Learn

The :text selector matches every <input type="text"> element — and since jQuery 1.5.2, bare <input> with no type attribute too. Always prefer input:text over bare :text.

01

Syntax

input:text

02

type=text

Single line

03

Official

Style + count

04

vs [type=]

No-type input

05

≠ textarea

Input only

06

Native CSS

Faster query

Introduction

Login forms, search bars, and name fields almost always use single-line text inputs. jQuery’s :text pseudo-class selects every input whose type is text — the default type when no type attribute is present.

Official jQuery documentation recommends prefixing with input — bare $(":text") implies $("*:text"). Since jQuery 1.5.2, :text matches inputs without a type attribute, which differs from the attribute selector [type=text].

Understanding the :text Selector

Think of :text as a shortcut for single-line text inputs:

  • input:text → every text-type input in scope.
  • <input> (no type) → matches :text since 1.5.2.
  • <input type="password"> → use :password instead.
  • <textarea> → not matched — different element tag.
💡
Beginner Tip

Do not confuse :text (selector) with .text() (method). The selector finds input fields; the method reads or writes text content on any element.

📝 Syntax

Official jQuery API form (since 1.0):

jQuery
jQuery( ":text" )

// recommended — prefix with input:
$( "input:text" )
$( "form input:text" )

// equivalent when type is explicit:
$( "input[type=text]" )

// :text vs [type=text] on bare <input>:
$( "input" ).is( ":text" );       // true (since 1.5.2)
$( "input" ).is( "[type=text]" ); // false

// native CSS (better performance):
document.querySelectorAll( 'input[type="text"]' )

// avoid on large pages:
$( ":text" )   // implies *:text

Parameters

  • No arguments — keeps elements whose effective type is text.

Return value

  • A jQuery object containing every matching text input (zero or more).

Official jQuery API example

jQuery
var input = $( "form input:text" ).css({
  background: "yellow",
  border: "3px red solid"
});

$( "div" )
  .text( "For this type jQuery found " + input.length + "." )
  .css( "color", "red" );

⚡ Quick Reference

Elementinput:textinput[type="text"]
<input type="text">MatchesMatches
<input> (no type)Matches (1.5.2+)No match
<input type="password">No matchNo match
<textarea>No matchNo match
Native querySelectorAllNot supportedSupported

📋 :text vs :password and [type="text"]

Single-line text vs masked input vs attribute-only matching.

:text
input:text

Plain text fields

:password
input:password

Masked secrets

[type=text]
input[type="text"]

Explicit attr only

textarea
$("textarea")

Multi-line text

Examples Gallery

Example 1 follows the official jQuery form input:text demo. Examples 2–5 cover the :text vs [type=text] difference, contrast with :password, scoped queries, and native performance.

📚 Official jQuery Demo

Style every text input in a form and report the count.

Example 1 — Official Demo: form input:text

Official jQuery demo — yellow background, red border, and match count in red text.

jQuery
var input = $( "form input:text" ).css({
  background: "yellow",
  border: "3px red solid"
});

$( "div" )
  .text( "For this type jQuery found " + input.length + "." )
  .css( "color", "red" );

$( "form" ).on( "submit", function( event ) {
  event.preventDefault();
} );
Try It Yourself

How It Works

jQuery finds text-type inputs inside the form, applies inline styles, and reports .length.

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

Official docs — bare <input> matches :text but not the attribute selector.

jQuery
console.log( $( "input" ).is( "[type=text]" ) ); // false
console.log( $( "input" ).is( ":text" ) );       // true

// Since jQuery 1.5.2 — implied type="text"
Try It Yourself

How It Works

Always set type="text" explicitly in HTML for clarity — but know how jQuery :text behaves when you do not.

📈 Practical Patterns

Password contrast, form scoping, and native queries.

Example 3 — input:text vs input:password

Style username fields without affecting password inputs in the same form.

jQuery
$( "input:text" ).addClass( "text-field" );
$( "input:password" ).addClass( "secret-field" );

// :text → plain text inputs only
// :password → masked password inputs only
Try It Yourself

How It Works

Each form pseudo-class maps to one input type — they never overlap on the same element.

Example 4 — Scoped Query: $("#searchForm input:text")

Target text inputs in one form only — skip unrelated forms on the page.

jQuery
$( "#searchForm input:text" ).attr( "placeholder", "Search…" );

// loginForm text inputs are not affected
Try It Yourself

How It Works

Prefix the form id before input:text to limit the matched set to one form context.

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

Official docs — use attribute selector in modern browsers for querySelectorAll speed.

jQuery
$( 'input[type="text"]' ).addClass( "field" );

// Pure DOM (no jQuery pseudo-class):
document.querySelectorAll( 'input[type="text"]' );
Try It Yourself

How It Works

Because :text is not standard CSS, attribute matching lets the browser optimize the query — but misses bare <input> without type.

🚀 Common Use Cases

  • Login forms — style or validate input:text username fields.
  • Search bars — bind keyup handlers on scoped text inputs.
  • Auto-focus$("#form input:text").first().focus() on load.
  • Clear fields.val("") on every text input in a filter form.
  • Trim whitespace — loop input:text and trim on blur.
  • Performance — prefer input[type="text"] when type is always explicit.

🧠 How jQuery Evaluates :text

1

Parse selector

Combine input with :text — optionally scope to a form id.

Query
2

Find candidates

Collect input elements in scope (or all elements if bare :text).

Scan
3

Filter by type

Keep inputs where type is text or missing (implied text since 1.5.2).

Match
4

Return collection

Chain .val(), .addClass(), or validation methods.

📝 Notes

  • Available since jQuery 1.0 — input elements of type text only.
  • Since 1.5.2 — bare <input> without type also matches :text.
  • jQuery extension only — not valid in native querySelectorAll(":text").
  • Always use input:text — bare :text implies universal scan.
  • Does not match textarea, password, email, or other specialized input types.
  • Not the same as jQuery .text() content method.

Browser Support

The :text pseudo-class is a jQuery extension and works in jQuery 1.0+ (no-type matching since 1.5.2). The equivalent input[type="text"] attribute selector is standard CSS and runs in native querySelectorAll in all modern browsers.

jQuery 1.0+ · extension

jQuery :text Selector

Use input:text in jQuery; use input[type="text"] for native speed.

100% jQuery + native attr
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: Explicit type="text" in HTML; :text also catches bare input since 1.5.2.

Conclusion

The :text selector matches every single-line text input — the official demo styles them and reports the match count.

Prefix with input, know the [type=text] difference for bare inputs, and use attribute selectors when native performance matters.

💡 Best Practices

✅ Do

  • Write $("#form input:text") for scoped queries
  • Set type="text" explicitly in HTML markup
  • Use input[type="text"] for native performance
  • Use :password for secret fields separately
  • Use $("textarea") for multi-line text areas

❌ Don’t

  • Confuse :text selector with .text() method
  • Use bare $(":text") on large pages
  • Expect :text to match textarea elements
  • Assume [type=text] catches bare <input>
  • Style without scoping when multiple forms exist

Key Takeaways

Knowledge Unlocked

Five things to remember about :text

Text-type inputs only.

5
Core concepts
02

No type

1.5.2+

Rule
input 03

Prefix

input:text

Tip
04

.text()

Method

Compare
demo 05

Official

Style count

Demo

❓ Frequently Asked Questions

:text selects every input element whose type is text — single-line text fields in forms. $("input:text") finds all text inputs in the search context. Available since jQuery 1.0.
Prefer $("input:text"). Bare $(':text') implies the universal selector and scans as $('*:text'), which is slower on large pages. Official jQuery docs recommend prefixing with input or another selector.
Since jQuery 1.5.2, :text also matches input elements with no type attribute (type="text" is implied). [type=text] matches only when the attribute is explicitly set. Official docs demonstrate: $("input").is(":text") is true for bare input, but .is("[type=text]") is false.
No. Official jQuery docs state that :text selects input elements of type text. Multi-line text areas use the textarea tag — gather those with $("textarea") or the broader :input pseudo-class instead.
No. :text is a selector for input[type=text] elements. .text() is a method that gets or sets text content on matched elements. They share a name but serve completely different purposes.
The official jQuery form demo styles $("form input:text") and reports how many were found — typically one or two text inputs among password fields, buttons, and other controls in the sample form.
Did you know?

HTML5 added specialized input types like email, search, and tel — none of them match :text. Only classic type="text" and bare <input> elements match. For HTML5 types, use attribute selectors such as input[type="email"] instead.

Continue to :checked Selector

After text inputs, learn how :checked filters live ticked and selected form state.

:checked selector 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.

6 people found this page helpful