:lt(index) (since jQuery 1.0) selects every element whose zero-based index in the matched set is less thanindex. It is a jQuery extension (not CSS) and is deprecated since 3.4. Prefer .slice(0, index).
Remember
// Preferred (official migration)
$("td").slice(0, 4); // same as :lt(4)
$("td").slice(0, -2); // same as :lt(-2)
// Legacy selector (deprecated 3.4)
$("td:lt(4)");
$("td:lt(-2)"); // negative since 1.8
// :lt(1) → only index 0 (like .first())
$("li").slice(0, 1);
Select with CSS first, then keep elements before an index.
Build a matched set with a pure CSS selector: $("td") or $("ul.nav li").
Chain .slice(0, index) to keep indices 0 … index - 1.
Use a negative end for “all but the last n”: .slice(0, -2).
Avoid putting :lt() inside the selector string in new code.
Remember: indexing is 0-based on the matched set, not CSS :nth-child.
Piece
Required?
Role
CSS selector
Yes
Builds the matched set
.slice(0, n)
Preferred
Keeps indices < n
:lt(n)
Legacy
Same idea inside the selector (deprecated)
Pseudocode
Pseudocode
build a matched set with a CSS selector
assign each element index 0, 1, 2, …
keep every element where index < n
→ same as .slice(0, n)
if n is negative:
count from the end of the set
keep everything before that end index
→ same as .slice(0, -abs)
Reference
Cheat Sheet
Keep these facts handy while filtering by index.
Topic
Detail
Prefer
$("elem").slice(0, n)
Legacy
$("elem:lt(n)") (deprecated 3.4)
Since
1.0 (negative index since 1.8)
Index model
0-based on the matched set
:lt(1)
Same as .first() / .eq(0)
vs :gt(n)
Before n vs after n (n itself excluded)
CSS?
No — jQuery extension
Official demo
$("td:lt(4)") / :lt(-2)
Try it
Live Preview
Mark the first three items with .slice(0, 3), try a negative end, or count matches.
Five list items below (indexes 0–4). .slice(0, 3) keeps 0, 1, 2.
Item 0
Item 1
Item 2
Item 3
Item 4
Result
Ready — pick an action and click Run.
Code
jQuery Examples
Short, copy-ready snippets. Use Try It Yourself for a live editor.
Example 1 — Official .slice(0, 4)
Mark the first four table cells (official :lt(4) idea, CSS-free).
Selector.:lt(2) still works but is deprecated since 3.4.
Habit. Write new code with .slice() only.
Edge Cases & Pitfalls
Check these when the “less than” filter surprises you.
deprecated
Avoid :lt() in new selectors
Deprecated since jQuery 3.4. Prefer $("elem").slice(0, n) after a CSS selector.
index
Zero-based, exclusive end
.slice(0, 4) keeps 0–3. Index 4 is not included. This is not CSS :nth-child (1-based).
scope
The set comes first
Indexes are assigned after the preceding selector. $("ul.nav li").slice(0, 2) and $("li").slice(0, 2) can differ.
perf
Not native CSS
:lt() cannot use querySelectorAll. Selecting with CSS first, then .slice(), is faster on large pages.
Compatibility
Browser Support
:lt() is a jQuery extension (not standard CSS). Available since 1.0 (negative index since 1.8), deprecated in 3.4. Prefer .slice(), which works in every browser that runs your loaded jQuery version.
✓ Deprecated · jQuery 1.0+
jQuery :lt() / .slice()
The selector still works in jQuery 3.x but is deprecated. Use .slice(0, n) for new code — same result, better practice.
1.0+jQuery since
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 3.4
Bottom line: Safe to learn for reading old code. Write new code with $("elem").slice(0, n) instead of $("elem:lt(n)").
Analysis
Performance Notes
Approach
Cost
Best for
$("ul.nav li").slice(0, 3)
Cheap
Scoped lists (preferred)
$("li").slice(0, 3)
Cheap–moderate
Page-wide first n items
$("li:lt(3)")
Moderate
Legacy only — avoid in new code
Pure CSS selection can use the browser engine; :lt() cannot. Chain .slice() after CSS for the best of both.
Remember
Key Takeaways
Role: keep elements with index < n in the matched set.
Prefer:.slice(0, n) over deprecated :lt(n).
0-based:.slice(0, 4) keeps 0–3; index 4 is out.
Negative:.slice(0, -2) keeps all but the last two.
One line: use .slice(0, n) to keep the first n matches — not the deprecated :lt(n) selector.
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. Available since jQuery 1.0.
Yes. :lt(1) keeps only index 0 — the same as :first and :eq(0). Prefer $("elem").first() or .slice(0, 1) in modern code.
Since jQuery 1.8, :lt(-index) counts from the end. Prefer .slice(0, -2), which keeps every element before the last two.
Yes — deprecated in jQuery 3.4. Official docs recommend .slice() instead: $("td").slice(0, 4) replaces $("td:lt(4)").
:lt() filters the jQuery matched set by 0-based position. :nth-child(n) is CSS and uses 1-based child position under a parent. Different models.
:lt(4) keeps indices 0–3. :gt(4) keeps indices after 4. Index 4 itself matches neither selector.