jQuery :first Selector

Beginner
5 min read
Updated: Nov 2026
3 examples
Selectors

Definition

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

Syntax

Start with these common calls. Keep them short and readable.

jQuery
// 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");
CallWhat it does
Base selectorBuilds the matched set (e.g. tr, li)
:first / .first()Keep index 0 of that set
Document orderMatches appear in DOM order

Load jQuery before your script (CDN or local file), then wrap DOM work in $(function () { ... }) when needed.

Parameters

ParameterDescription
Step 1Select candidates with a pure CSS selector: $("tr"), $("ul li").
Step 2Take the first: .first() (recommended) or legacy :first.
Step 3Chain actions — .text(), .addClass(), events.

Return Value

Return ValueDescription
See examplesCheck the examples below for what this API returns in common cases.

jQuery Examples

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.

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.

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.

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 Selector tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

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