jQuery.sub() (alias $.sub) created a new copy of jQuery whose methods you could change without affecting the global jQuery / $ object. It took no arguments and returned that copy (jQuery 1.5–1.8).
Remember
var sub$ = jQuery.sub(); // copy of jQuery
sub$.fn.myCustomMethod = function () {
return "just for me";
};
sub$("body").myCustomMethod(); // "just for me"
typeof jQuery("body").myCustomMethod; // undefined
// Not a sandbox — events / Ajax / data still use main jQuery
Historical pattern only — requires jQuery 1.5–1.8.
Call var copy = jQuery.sub() to get a private jQuery function.
Add or override methods on copy.fn (not on global jQuery.fn).
Use copy(selector) (or copy(this)) so chains see your private methods.
Remember: events, data, and Ajax still run through the main jQuery.
Piece
Required?
Role
Arguments
None
No parameters
Return
—
A new jQuery constructor/function copy
Versions
—
1.5–1.8 only (gone in 1.9+)
Pseudocode
Pseudocode
function sub():
copy = clone of jQuery function + jQuery.fn
// copy.fn can be extended without changing global jQuery.fn
return copy
// Use cases (official):
// 1) Private methods only on the copy
// 2) Override methods (e.g. .remove) on the copy
// 3) Plugin returns plugin(this) so chain sees plugin methods
// Not isolation: events / data / Ajax → main jQuery
Reference
Cheat Sheet
Keep these facts handy when reading legacy plugin code.
Topic
Detail
Syntax
jQuery.sub()
Added
jQuery 1.5
Deprecated
jQuery 1.7
Removed
jQuery 1.9
Isolation?
No — not a sandbox
vs noConflict
Forks API vs releases global name
Today
Modules / widget factory
Try it
Live Preview
Runs on jQuery 1.8.3 (still has $.sub). Pick a demo action from the official use cases.
Legacy browser demo of jQuery.sub() — removed in jQuery 1.9+.
Result
var sub$ = jQuery.sub();
sub$.fn.myCustomMethod = …
sub$("body").myCustomMethod()
→ "just for me"
Code
jQuery Examples
Official patterns from the API docs. Labs use jQuery 1.8.3 (except example 5, which proves removal on 3.x).
Example 1 — Private Method on a Sub
Add a method that exists only on the copy — not on global jQuery.
jQuery
(function () {
var sub$ = jQuery.sub();
sub$.fn.myCustomMethod = function () {
return "just for me";
};
console.log(sub$("body").myCustomMethod()); // "just for me"
})();
console.log(typeof jQuery("body").myCustomMethod); // undefined
Fork.myjQuery is a copy; global $.fn.remove is unchanged.
Wrap. The override fires a "remove" event, then calls the real remove.
Scope. Only removals done through myjQuery get the extra event.
Lesson. Regular $("#item").remove() on global jQuery would not trigger this hook.
Example 3 — Plugin That Returns Sub Methods
Expose open / close only after calling .myplugin().
jQuery
var plugin = jQuery.sub();
plugin.fn.extend({
open: function () { return this.show(); },
close: function () { return this.hide(); }
});
jQuery.fn.myplugin = function () {
this.addClass("plugin");
return plugin(this); // chain sees open/close
};
$("#main").myplugin().open();
// $("#main").open() alone would fail — open is on the sub only
Legacy only. Reading old code? Pin jQuery ≤1.8 or rewrite the plugin.
Replacement. Use modules or the widget factory for new work.
Edge Cases & Pitfalls
Check these before assuming $.sub() still exists or isolates anything.
removed
Gone since jQuery 1.9
typeof $.sub === "undefined" on modern builds. Calling it throws. Do not ship new code that depends on it.
sandbox
Not a sandbox
Events, Ajax, and .data() still go through main jQuery. Official docs warn: isolation was never the goal.
chain
Private methods need the sub collection
After leaving a subbed chain (or starting from global $), plugin-only methods disappear. Return plugin(this) when you need them to stay.
alt
Prefer widget factory / modules today
Official guidance: for plugin development, strongly consider the jQuery UI widget factory (state + sub-methods) or plain modules.
Compatibility
Browser Support
jQuery.sub() needed a browser DOM and jQuery 1.5–1.8. It was removed in jQuery 1.9 and is absent from jQuery 3.x — not available in Node.js without a legacy jQuery build + DOM.
✓ Removed 1.9 · Legacy only
jQuery.sub()
Historical API: browsers with jQuery 1.5–1.8. Modern jQuery builds do not include $.sub(). Use modules or the widget factory instead.
LegacyjQuery 1.5–1.8 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
$.sub()Removed
Bottom line: Do not use $.sub() in new projects. Read this page to understand legacy plugins; rewrite with modules or the widget factory.
Analysis
Performance Notes
Approach
Cost
Best for
jQuery.sub()
Copy overhead
Legacy private API forks (historical)
IIFE / module helpers
Negligible
Private functions today
Widget factory
Modest
Stateful plugins with methods
Performance is not the reason sub() was removed — maintainability and clearer plugin patterns were. Prefer modules over copying the whole jQuery API.
Remember
Key Takeaways
Role:$.sub() forked jQuery so you could extend a private copy.
Status: deprecated 1.7, removed 1.9 — absent in jQuery 3.
Not a sandbox: events / Ajax / data still use main jQuery.
Today: modules or the widget factory — not $.sub().
One line:jQuery.sub() made a private editable copy of jQuery for plugins — useful historically, removed in 1.9, and never a true sandbox.
Frequently Asked Questions
jQuery.sub() returned a new copy of the jQuery function whose properties and methods you could change without modifying the global jQuery / $ object. Private plugin methods and method overrides lived on that copy. Added in jQuery 1.5.
No. It was deprecated in jQuery 1.7 and removed in jQuery 1.9. Modern jQuery 3.x does not include $.sub(). Try-it labs on this page load jQuery 1.8.3 so you can still run authentic historical demos.
No. Official docs stress that sub() is not sandbox isolation. Events, .data(), and Ajax still go through the main jQuery. Only the jQuery function object and its fn methods are copied so you can extend or override them privately.
Two cases: (1) override methods like .remove() on a private copy without changing global jQuery, and (2) basic plugin encapsulation so helper methods exist only on the subbed instance. For new plugins, prefer the jQuery UI widget factory or plain modules.
noConflict() restores the previous global $ and can release the jQuery name — it does not create a fork of the API. sub() kept the same global jQuery and gave you a second, editable copy for private extensions.
Use ES modules or IIFEs for private helpers, jQuery.fn plugins that return the original collection, or the jQuery UI widget factory for stateful plugins. Do not rely on $.sub() in new code — it is gone from modern jQuery.