jQuery :first Selector

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

What Is :first?

:first (since jQuery 1.0, deprecated 3.4) selects exactly one element — the first in the matched set, in document order. It equals :eq(0) / :lt(1). Prefer $("…").first() in new code.

Remember
// Legacy (still works; deprecated 3.4)
$("tr:first");

// Recommended
$("tr").first();

// Same idea
$("tr:eq(0)");
$("tr:lt(1)");

// Not the same as :first-child (can match many)
$("li:first-child");
NeedUse
First in a matched set$("li").first() (recommended)
Legacy pseudo$("li:first") ⚠ deprecated 3.4
Index 0$("li:eq(0)")
First child per parent$("li:first-child")
Last in a set$("li").last()

How to Use :first / .first()

Build a set with a CSS selector, then keep only the first item.

  1. Select candidates with a pure CSS selector: $("tr"), $("ul li").
  2. Take the first: .first() (recommended) or legacy :first.
  3. Chain actions — .text(), .addClass(), events.
  4. Remember: one match only — not one per parent.
  5. For per-parent firsts, use :first-child instead.
PieceRequired?Role
Base selectorYesBuilds the matched set (e.g. tr, li)
:first / .first()YesKeep index 0 of that set
Document order—Matches appear in DOM order

Pseudocode

Pseudocode
set = all elements matching the left selector
      (in document order)

result = set[0] if set is not empty
          else empty

// .first() does the same after the set is built
// :first is a jQuery-only filter (not native CSS)

Cheat Sheet

Keep these facts handy when picking the first match.

TopicDetail
Selector$("elem:first") ⚠ deprecated 3.4
Method$("elem").first() ✓ preferred
SincejQuery 1.0
Matches0 or 1
Equivalent:eq(0), :lt(1)
vs :first-childOne from set vs one per parent
CSS?No — jQuery extension
Official demo$("tr:first")

Live Preview

Mark the first row, compare with .first() / :first-child, or count matches.

Sample: one table with three rows. :first / .first() hit one row; td:first-child hits every row’s first cell.

Row 1A
Row 2B
Row 3C
Result
Ready — pick an action and click Run.

jQuery Examples

Short, copy-ready snippets. Prefer .first() for new code.

Example 1 — Official tr:first

Mark the first table row in the matched set.

jQuery
$("tr:first td").prepend("[first] ");
Try It Yourself

How It Works

  1. Match. $("tr") finds every row.
  2. Filter. :first keeps only index 0.
  3. Mark. Prepend a label in that row.
  4. Note. Prefer $("tr").first() in new code.

Example 2 — Recommended .first()

Official migration path after jQuery 3.4.

jQuery
$("tr").first().find("td").prepend("[first] ");
Try It Yourself

How It Works

  1. CSS. Select rows with a pure CSS selector.
  2. Method. .first() keeps one element.
  3. Act. Update cells inside that row.
  4. Perf. Lets the browser use querySelectorAll first.

Example 3 — Same as :eq(0)

Official docs: :first equals :eq(0) (and :lt(1)).

jQuery
var a = $("tr:first").text();
var b = $("tr:eq(0)").text();
$("#out").text("first=[" + a + "] eq=[" + b + "]");
Try It Yourself

How It Works

  1. Both. Read text from :first and :eq(0).
  2. Same. Both resolve to index 0.
  3. Also. :lt(1) yields the same single item.
  4. Modern. Still prefer .first() or .eq(0) methods.

Example 4 — :first vs :first-child

One from the set versus one first child per parent.

jQuery
var one = $("ul li:first").length;
var many = $("ul li:first-child").length;
$("#out").text(":first → " + one + ", :first-child → " + many);
Try It Yourself

How It Works

  1. :first. First li in the whole set → 1.
  2. :first-child. First li in each ul → 2.
  3. Compare. Counts show the difference.
  4. Choose. Set-first vs per-parent first.

Example 5 — First List Item with .first()

Practical pattern: mark only the first item in one list context.

jQuery
$("#menu li").first().prepend("* ");
Try It Yourself

How It Works

  1. Scope. Select items under #menu.
  2. First. .first() keeps one item.
  3. Mark. Prepend a bullet marker.
  4. Rest. Later items stay unchanged.

Edge Cases & Pitfalls

These mix-ups show up most often with :first.

deprecated

Do not use :first in new code

Deprecated in 3.4. Prefer $("sel").first().

vs child

Not the same as :first-child

:first = one from the set. :first-child = one per parent.

perf

Not native CSS

:first skips querySelectorAll. Select with CSS, then .first().

empty

Empty set stays empty

If nothing matched, .first() / :first returns an empty jQuery object.

Browser Support

:first has been part of jQuery since 1.0. Deprecated in 3.4 in favor of .first(). It is a jQuery extension — not a CSS selector — so native querySelectorAll cannot run it alone.

✓ Deprecated · jQuery 1.0+

jQuery :first

Works in jQuery builds that still include it, but new code should use .first() after a CSS selector.

Legacy jQuery extension
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: Fine for reading old code. For new projects, always use $("sel").first().

Performance Notes

ApproachCostBest for
$("tr").first()BestNew code — CSS then method
$("tr:first")Slower pathLegacy only
$("tr").filter(":first")OKOfficial note when filtering after CSS

Because :first is not CSS, jQuery cannot hand the whole query to the browser. Select first, then narrow with .first().

Key Takeaways

  • Role: keep the first element in a matched set (0 or 1).
  • Prefer: $("sel").first() since jQuery 3.4.
  • Equals: :eq(0) / :lt(1) — not :first-child.
  • Not CSS: jQuery extension — slower than native selectors alone.

One line: :first picks one element from a set — learn it for old code, write .first() in new code.

Frequently Asked Questions

:first selects exactly one element — the first in the matched set, in document order. $("tr:first") matches only the first table row. Available since jQuery 1.0; deprecated in 3.4.
Yes. Official docs state :first is equivalent to :eq(0). It can also be written as :lt(1).
Yes — deprecated in jQuery 3.4. Prefer a pure CSS selector plus .first(): $("tr").first() instead of $("tr:first").
:first returns one element from the whole matched set. :first-child can return many — one per parent.
No. :first is a jQuery extension. It does not work in native querySelectorAll and skips the native selector performance boost.
:first narrows a set built by what comes before it — e.g. $("li:first") or $("li").first(). Bare $(":first") is not a useful pattern.

Next: :last Selector

Learn the mirror filter for the last element in a matched set.

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

15 people found this page helpful