jQuery :first Selector

Beginner
⏱️ 9 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
jQuery extension · deprecated 3.4

What You’ll Learn

The :first selector matches exactly one element — the first in the matched set, in document order. Equivalent to :eq(0). jQuery extension since 1.0; deprecated in 3.4 — prefer the .first() method.

01

Syntax

tr:first

02

One match

Single element

03

Official

tr italic

04

= :eq(0)

Equivalent

05

vs :first-child

Many per parent

06

.first()

Modern replacement

Introduction

When you have many matching elements — table rows, list items, or cards — you often need only the first one in document order. The jQuery :first pseudo-class narrows a matched set to that single leading element.

jQuery has supported :first since version 1.0. Official documentation states it selects the first matched DOM element and is equivalent to :eq(0). As of jQuery 3.4, the selector is deprecated — use .first() on a CSS-selected collection instead.

Understanding the :first Selector

Think of :first as “keep only index 0 from this matched set”:

  • $("tr:first") → one row — the first tr in document order.
  • $("li:first") → one list item — the very first li on the page (in scope).
  • Equivalent to :eq(0) and :lt(1) per official jQuery docs.
  • Not the same as :first-child — that can match one element per parent.
💡
Beginner Tip

Need the first item in every list? Use $("ul li:first-child"), not $("li:first"). The former returns many; the latter returns one.

📝 Syntax

Official jQuery API form (since 1.0; deprecated 3.4):

jQuery
jQuery( ":first" )

// typical usage — prefix with element:
$( "tr:first" )
$( "ul.nav li:first" )
$( "div.card:first" )

// equivalents:
$( "tr:eq(0)" )
$( "tr:lt(1)" )

// modern replacement (jQuery 3.4+ guidance):
$( "tr" ).first()

Parameters

  • No arguments — keeps the first element from the matched set that precedes :first.

Return value

  • A jQuery object containing zero or one element.
  • Empty collection when the preceding selector matched nothing.

Official jQuery API example

jQuery
$( "tr:first" ).css( "font-style", "italic" );

⚡ Quick Reference

Goal:first.first()
First table rowtr:first$("tr").first()
Same as :eq(0)li:first$("li").eq(0)
First li in documentOne elementOne element
First li in each listNot :firstUse li:first-child
Native CSSNot supportedjQuery method only

📋 :first vs :eq(0), .first(), and :first-child

Set index vs sibling position — one global match vs one per parent.

:first
li:first

One element total

:eq(0)
li:eq(0)

Equivalent

.first()
$("li").first()

Modern replacement

:first-child
li:first-child

One per parent

Examples Gallery

Example 1 follows the official jQuery tr:first demo. Examples 2–5 cover equivalence with :eq(0), migration to .first(), contrast with :first-child, and scoped list selection.

📚 Official jQuery Demo

Italicize the first table row in the matched set.

Example 1 — Official Demo: tr:first

Official jQuery demo — Row 1 italic; Row 2 and Row 3 unchanged.

jQuery
$( "tr:first" ).css( "font-style", "italic" );
Try It Yourself

How It Works

All tr elements form the matched set; :first keeps only index 0 — the first row in document order.

Example 2 — Equivalence: :first and :eq(0)

Official docs — both select the same single element from the matched set.

jQuery
console.log( ":first →", $( "li:first" ).text() );
console.log( ":eq(0) →", $( "li:eq(0)" ).text() );
console.log( "Same element?", $( "li:first" ).is( $( "li:eq(0)" )[0] ) );
Try It Yourself

How It Works

:first, :eq(0), and :lt(1) all narrow to the element at zero-based index 0.

📈 Practical Patterns

Modern migration, sibling contrast, and scoped queries.

Example 3 — Modern Code: .first() Method

jQuery 3.4+ guidance — replace :first with a CSS selector plus .first().

jQuery
// legacy (deprecated selector):
// $( "tr:first" ).css( "font-style", "italic" );

// recommended:
$( "tr" ).first().css( "font-style", "italic" );
Try It Yourself

How It Works

Separating the CSS selector from index filtering improves clarity and avoids deprecated pseudo-classes in selector strings.

Example 4 — :first vs :first-child

Show why :first returns one item globally while :first-child returns one per list.

jQuery
$( "li:first" ).addClass( "one" );
$( "li:first-child" ).addClass( "fc" );

console.log( ":first →", $( "li:first" ).length );
console.log( ":first-child →", $( "li:first-child" ).length );
Try It Yourself

How It Works

Official docs: while :first matches only a single element, :first-child can match more than one — one for each parent.

Example 5 — Scoped Query: ul.nav li:first

Limit scope so “first” means the first item in a specific navigation list.

jQuery
$( "ul.nav li:first" ).css({
  fontWeight: "bold",
  color: "#2563eb"
});
Try It Yourself

How It Works

Prefixing with ul.nav builds a smaller matched set — the first match is the lead nav link, not the first li on the entire page.

🚀 Common Use Cases

  • Table headers — style tr:first or thead tr:first for emphasis.
  • Lead list item — highlight the first entry in a flat collection with li:first.
  • First card in a grid.card:first for featured layout (legacy code).
  • Legacy maintenance — understand :first when reading older jQuery projects.
  • Migration — replace with $("selector").first() in modern codebases.
  • Performance — select with CSS first, then .filter(":first") or .first().

🧠 How jQuery Evaluates :first

1

Build matched set

Evaluate the selector before :first — e.g. all tr elements.

Query
2

Order by document

Elements stay in document order — official docs note this explicitly.

Index
3

Keep index 0

:first discards all but the first element — same as :eq(0).

Filter
4

Return collection

Chain .css() or other jQuery methods on zero or one element.

📝 Notes

  • Available since jQuery 1.0 — deprecated in 3.4; prefer .first().
  • Equivalent to :eq(0) and :lt(1) — official jQuery documentation.
  • Matches only one element — unlike :first-child which can match many.
  • jQuery extension — not valid in native querySelectorAll.
  • For performance, use a pure CSS selector first, then .filter(":first") or .first().
  • Do not confuse with CSS :first-child or :first-of-type — different rules entirely.

Browser Support

The :first pseudo-class is a jQuery extension — not standard CSS — and works in jQuery 1.0+. It is deprecated in 3.4+; use .first() instead. The method works in all browsers that support jQuery.

jQuery 1.0+ · deprecated 3.4

jQuery :first Selector

Use $("tr").first() in new code — not tr:first in selector strings.

100% jQuery only
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
:first Deprecated

Bottom line: Migrate to .first() — select with CSS, then filter in jQuery.

Conclusion

The :first selector matches exactly one element — the first in the matched set. The official tr:first demo italicizes Row 1 only.

Remember equivalence with :eq(0), distinguish it from :first-child, and migrate to .first() in jQuery 3.4+ projects.

💡 Best Practices

✅ Do

  • Use $("tr").first() in new jQuery code
  • Scope queries — ul.nav li:first when needed
  • Choose :first-child when every parent needs a first item
  • Remember :first equals :eq(0) in legacy code
  • Select with CSS first for better performance

❌ Don’t

  • Use :first in new selector strings (deprecated 3.4)
  • Confuse :first with :first-child or :first-of-type
  • Assume :first returns one item per parent
  • Use bare $(":first") without a preceding selector
  • Expect :first to work in querySelectorAll

Key Takeaways

Knowledge Unlocked

Five things to remember about :first

First element in the matched set only.

5
Core concepts
0 02

= :eq(0)

Equivalent

Rule
03

Not :first-child

Per parent differs

Compare
demo 04

Official

tr italic

Demo
.first() 05

Deprecated

Use method

Tip

❓ Frequently Asked Questions

:first selects exactly one element — the first in the matched set that precedes it, in document order. $("tr:first") matches only the first table row among all tr elements in scope. Available since jQuery 1.0.
Yes. Official jQuery documentation states that :first is equivalent to :eq(0). It could also be written as :lt(1). All three return a single element at index 0 of the matched set.
Yes — deprecated in jQuery 3.4. Official docs recommend removing :first from selectors and using the .first() method after a pure CSS selector instead: $("tr").first() rather than $("tr:first").
:first returns one element total from the matched set. :first-child can return many — one per parent. Official docs highlight this distinction explicitly.
No. :first is a jQuery extension and not part of the CSS specification. It does not work in native querySelectorAll. Use .first() on a CSS-selected collection for modern code.
:first always follows a selector that builds the matched set — e.g. $("li:first") not $(":first"). Index selectors (:first, :eq, :lt, :gt, :even, :odd) narrow the set produced by what comes before them.
Did you know?

:first could also be written as :lt(1) — both keep elements with index less than 1, which is only index 0. Official jQuery docs list all three forms as equivalent.

Continue to :last Selector

Learn the mirror of :first — pick the last element in a matched set, with the official table row demo.

:last 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