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
Fundamentals
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].
Concept
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.
Foundation
📝 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" );
Cheat Sheet
⚡ Quick Reference
Element
input:text
input[type="text"]
<input type="text">
Matches
Matches
<input> (no type)
Matches (1.5.2+)
No match
<input type="password">
No match
No match
<textarea>
No match
No match
Native querySelectorAll
Not supported
Supported
Compare
📋 :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
Hands-On
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();
} );
Explicit type="text" inputs → .field class
Works in querySelectorAll — no :text extension needed
How It Works
Because :text is not standard CSS, attribute matching lets the browser optimize the query — but misses bare <input> without type.
Applications
🚀 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.
Important
📝 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.
Compatibility
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 ChromeAll versions · Desktop & Mobile
Full support
Mozilla FirefoxAll versions · Desktop & Mobile
Full support
Apple SafariAll versions · macOS & iOS
Full support
Microsoft EdgeAll versions · Chromium & Legacy
Full support
Internet ExplorerIE 6+ · Legacy environments
Full support
OperaAll modern versions
Full support
:textUniversal
Bottom line: Explicit type="text" in HTML; :text also catches bare input since 1.5.2.
Wrap Up
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.
: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.