.andSelf() (jQuery 1.2–2.x) merges the previous stack set with the current set — same idea as .addBack() with no selector. It takes no arguments. Learn it to read legacy code; write .addBack() in new work.
Remember
// Legacy (jQuery 1.2–2.x only):
$("li.third-item").nextAll().andSelf()
// Modern (jQuery 1.8+ / 3.x):
$("li.third-item").nextAll().addBack()
// Same union — rename only
// andSelf() never had a selector filter
// addBack(selector) can filter the union
Same chaining pattern as .addBack() — then rename for modern jQuery.
Select a starting set (e.g. $("li.third-item")).
Traverse with .nextAll(), .find(), etc. (pushes a new stack set).
Call .andSelf() to union previous + current (jQuery 1.2–2.x).
Migrate: change .andSelf() → .addBack().
On jQuery 3, never call .andSelf() — it throws.
Piece
Required?
Role
Prior traversal
Yes
Something that pushed a new stack set
.andSelf()
Yes (legacy)
Merge previous + current (no args)
jQuery version
1.2–2.x
Missing in jQuery 3.0+
Modern replacement
—
.addBack() (1.8+)
Pseudocode
Pseudocode
// Legacy:
call $(set).nextAll().andSelf()
→ same as .addBack() with no selector
// Migration:
replace ".andSelf()" with ".addBack()"
if you need a filter:
use .addBack(selector) // andSelf never supported this
// jQuery 3:
if .andSelf is undefined → TypeError
Reference
Cheat Sheet
Keep the rename and version cutoffs clear.
Topic
Detail
Syntax
.andSelf() — no arguments
Added
jQuery 1.2
Deprecated
jQuery 1.8
Removed
jQuery 3.0
Replacement
.addBack() (identical no-arg form)
vs .end()
Union vs previous-only
Selector filter?
No — use .addBack(sel)
Try it
Live Preview
This demo loads jQuery 2.2.4 so .andSelf() still exists. Compare it with .addBack() and .end().
list item 1
list item 2
list item 3
list item 4
list item 5
On jQuery 2.x, .andSelf() and .addBack() both keep items 3–5. On jQuery 3, only .addBack() works.
Result
Ready — choose a call and click Run.
Code
jQuery Examples
Legacy snippets use jQuery 2.2.4 so .andSelf() runs. Migration labs use jQuery 3.7.1 with .addBack().
Example 1 — Legacy: nextAll() + andSelf()
Same result as the modern .addBack() list demo (jQuery 2.x).
div.panel [both]
First Paragraph [both]
Second Paragraph [both]
How It Works
find. Moves from the panel to its paragraphs.
andSelf. Unions the panel back into the set.
Mark. Parent and children get the same suffix.
Migrate. Swap to .addBack() for jQuery 3.
Example 3 — Migrate .andSelf() → .addBack()
One-to-one rename; optional filter only exists on .addBack().
jQuery
// Before (breaks on jQuery 3):
// $("div.panel").find("p").andSelf().append(" [old]");
// After:
$("div.panel").find("p").addBack().append(" [new]");
// Need a filter? andSelf never could — use:
// $("div.panel").find("p").addBack(".panel");
div.panel [new]
paragraphs [new]
(Runs on jQuery 3 via .addBack())
How It Works
Find. Search the codebase for .andSelf(.
Replace. Change each call to .addBack().
Same union. No-arg behavior matches the old method.
Bonus. Use .addBack(sel) if you need a filter.
Example 4 — .andSelf() vs .end()
Union keeps both groups; .end() restores the previous set only.
jQuery
var a = $("li.third-item").nextAll().andSelf().length; // 3
var b = $("li.third-item").nextAll().end().length; // 1
$("#out").text("andSelf → " + a + "\\nend → " + b);
.andSelf missing — use .addBack()
items 3–5 marked [ok]
How It Works
Check.jQuery.fn.andSelf is undefined on jQuery 3.
Avoid call. Calling it would throw a TypeError.
Use addBack. The modern method is always present on 1.8+ / 3.x.
Upgrade. Fix source before shipping jQuery 3.
Edge Cases & Pitfalls
Where legacy code breaks during upgrades.
jquery 3
.andSelf is not a function
Removed in 3.0. Search the project for .andSelf( before upgrading.
name
Not “current element self”
It merges the previous stack set. That confusion is why jQuery renamed it to .addBack().
filter
No selector argument
.andSelf() never accepted a filter. Use .addBack(selector) after migration.
migrate
jQuery Migrate is temporary
Migrate may restore .andSelf() during upgrades — still replace it in source.
Compatibility
Browser Support
.andSelf() existed in jQuery 1.2 through 2.x. It was deprecated in 1.8 and removed in 3.0. Use .addBack() (jQuery 1.8+) everywhere — including all jQuery 3.x builds.
✓ Deprecated · removed in 3.0
jQuery .andSelf()
Works only on jQuery 1.2–2.x. Replacement .addBack() works on jQuery 1.8+ and all 3.x browsers that run jQuery.
LegacyUse .addBack() instead
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
.andSelf()Removed
Bottom line: Read .andSelf() in old code; write .addBack() in all new and migrated projects. Plan a find-and-replace before jQuery 3.
Analysis
Performance Notes
Approach
Cost
Best for
.addBack()
Same as andSelf
All modern code
.andSelf()
Same (legacy)
jQuery 1.2–2.x only
Stay on jQuery 2 for andSelf
Risk
Avoid — migrate instead
There is no performance reason to keep .andSelf(). The cost matches .addBack(); the risk is a hard break on jQuery 3.
One line: read .andSelf() as .addBack() — and never ship the old name on jQuery 3.
Frequently Asked Questions
.andSelf() adds the previous set of elements on jQuery's internal traversal stack to the current set — the same union as .addBack() with no selector. It takes no arguments. Added in jQuery 1.2.
Yes for the no-argument form. jQuery renamed .andSelf() to .addBack() in 1.8. .addBack() can also take an optional selector filter; .andSelf() never could.
Deprecated in jQuery 1.8 because the name was confusing. Removed in jQuery 3.0. Official docs: use .addBack() instead, which should work identically.
No. Calling it throws because the method no longer exists. Replace every .andSelf() with .addBack() before upgrading.
Find-and-replace .andSelf() with .addBack(). For a filtered union, use .addBack(selector) — something .andSelf() never supported.
Legacy themes, old plugins, and older Stack Overflow answers. Read it as .addBack() when migrating to jQuery 3.