The :lt(index) selector matches every element whose zero-based index in the matched set is less thanindex. Negative indices since 1.8. jQuery extension since 1.0; deprecated in 3.4 — prefer .slice(0, index).
01
Syntax
td:lt(4)
02
< index
Strictly before
03
Official
yellow + red
04
Negative
Since 1.8
05
.slice()
(0, n)
06
:lt(1)
Same as :first
Fundamentals
Introduction
Index filters let you target a subset of an already matched collection — style the first few table cells, highlight leading list items, or trim trailing rows from a batch operation. The jQuery :lt(index) pseudo-class selects elements before a given position in the matched set.
jQuery has supported :lt() since version 1.0; negative indices since 1.8. Official documentation states that index-related selectors filter the set matched by what precedes them and use 0-based indexing like JavaScript arrays — unlike CSS :nth-child(n), which is 1-based.
Concept
Understanding the :lt() Selector
Think of :lt(n) as “everything before index n in this matched set”:
$("td:lt(4)") → TD #0, #1, #2, #3 — indices 0 through 3 (official demo yellow cells).
$("li:lt(2)") → the first two list items — indices 0 and 1.
:lt(1) matches index 0 only — equivalent to :first and :eq(0).
Negative :lt(-2) since 1.8 — official demo colors TD #0–#6 red text.
💡
Beginner Tip
:lt(3) maps to .slice(0, 3) when migrating — pass the lt index as the second argument to .slice(). Need exactly one element at an index? Use :eq(n) or .eq(n) instead.
Foundation
📝 Syntax
Official jQuery API form (since 1.0; negative since 1.8; deprecated 3.4):
Range before an index vs after vs single pick vs first element.
:lt(n)
td:lt(4)
Index < n
:gt(n)
td:gt(4)
Index > n
:eq(n)
td:eq(4)
Exactly index n
:first / :lt(1)
td:first
Index 0 only
.slice(0, n)
.slice(0, 4)
Modern :lt(4)
Hands-On
Examples Gallery
Example 1 follows the official jQuery td:lt(4) and td:lt(-2) demo. Examples 2–5 cover :lt(1) as :first, .slice() migration, contrast with :gt(), and navigation list trimming.
📚 Official jQuery Demo
Yellow background on TD #0–#3; red text on TD #0–#6 via :lt(-2).
Example 1 — Official Demo: td:lt(4) and td:lt(-2)
Official jQuery demo — cells #0–#3 yellow; cells #0–#6 red text.
jQuery extension — not valid in native querySelectorAll.
For performance, use a CSS selector first, then .slice(0, index).
Prior to jQuery 1.8, a negative index was not accepted.
Compatibility
Browser Support
The :lt() pseudo-class is a jQuery extension — not standard CSS — and works in jQuery 1.0+ (negative indices 1.8+). It is deprecated in 3.4+; use .slice() instead. The method works in all browsers that support jQuery.
✓ jQuery 1.0+ · deprecated 3.4
jQuery :lt() Selector
Use $("td").slice(0, 4) in new code — not td:lt(4) in selector strings.
100%jQuery only
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
:lt()Deprecated
Bottom line: Migrate to .slice(0, index) — select with CSS, then filter in jQuery.
Wrap Up
Conclusion
The :lt(index) selector matches every element whose index in the matched set is less than index — the official demo yellows TD #0–#3 and reddens TD #0–#6 via :lt(-2).
Remember 0-based indexing, the .slice(0, index) migration path, and that :lt(1) equals :first when you need only the leading element.
Use :lt() in new selector strings (deprecated 3.4)
Confuse :lt(n) with :gt(n) — before vs after
Assume 1-based indexing — lt is 0-based
Expect :lt to work in querySelectorAll
Forget :lt(4) excludes index 4 itself
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about :lt()
Elements before index n in the matched set.
5
Core concepts
<01
:lt(n)
Index < n
API
0,n02
.slice()
Migration
Tip
003
0-based
Like arrays
Rule
demo04
Official
td yellow
Demo
1st05
:lt(1)
= :first
API
❓ Frequently Asked Questions
:lt(index) selects every element whose zero-based index in the matched set is less than index. $("td:lt(4)") matches TD #0 through #3 (indices 0, 1, 2, 3) in the official demo. Available since jQuery 1.0.
Yes — :lt(1) selects elements with index less than 1, which is only index 0. That is equivalent to :first and :eq(0): exactly one element, the first in the matched set.
Since jQuery 1.8, :lt(-index) counts backwards from the last element. In the official demo, $("td:lt(-2)") turns red text on every cell before the -2nd from the end — TD #0 through #6 among nine TD elements (indices 0–8).
Yes — deprecated in jQuery 3.4. Official docs recommend removing :lt() from selectors and using .slice() instead: $("td").slice(0, 4) replaces $("td:lt(4)") — pass the lt index as the second argument to slice.
:lt() filters the jQuery matched set by 0-based position after the preceding selector. :nth-child(n) is CSS — it picks elements that are the nth child of their parent (1-based). They use different indexing models.
:lt(4) keeps indices 0, 1, 2, 3 — strictly before index 4. :gt(4) keeps indices 5, 6, 7, 8 — strictly after index 4. Index 4 itself matches neither selector.
Did you know?
The :first selector could be written as :lt(1) — both match exactly one element at index 0 in the matched set. Official docs note this equivalence when explaining index filters.