.size() returned the number of elements in a jQuery collection (since 1.0). It was functionally the same as .length, but .length is preferred because it skips a function call. Official docs: deprecated in 1.8, removed in 3.0.
Remember
// Legacy (jQuery 1.x / 2.x only):
// $("li").size()
// Modern — use this everywhere:
$("li").length
// Same count, both used to alert "2" for two <li> items
alert("Size: " + $("li").length);
Length stays. Counting still works via the property.
Audit first. Migrate before bumping jQuery.
Edge Cases & Pitfalls
Watch these when reading legacy code or upgrading jQuery.
removed
Gone in jQuery 3
.size() throws. Replace with .length before upgrading.
parens
Property, not method
Write .length — not .length().
scope
Only the matched set
Descendants are not counted unless they are in the selection.
plugins
Old plugins may still call size
Audit third-party scripts when moving to jQuery 3+.
Compatibility
Browser Support
.size() existed in jQuery 1.0–2.x (deprecated since 1.8). It was removed in 3.0. Use .length in all modern browsers with jQuery 3+.
✓ Removed in jQuery 3.0 · Use .length
jQuery .size() → .length
.length works wherever jQuery runs in the browser. .size() only existed before jQuery 3.
N/ALegacy method
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
.lengthAll jQuery
Bottom line: Do not call .size() on jQuery 3+. Count with $(sel).length instead.
Analysis
Performance Notes
Approach
Cost
Best for
.length
Lowest
All modern counting
.size()
Slightly higher
Legacy only (removed in 3.0)
Official reason to prefer .length: it avoids a function call. For beginners the bigger win is compatibility with jQuery 3+.
Remember
Key Takeaways
Role: counted matched elements — same number as .length.
Status: deprecated 1.8, removed 3.0.
Replace:.size() → .length.
Empty: count is 0, not an error.
One line: do not use .size() — count with $(sel).length.
Frequently Asked Questions
.size() returned an integer: how many elements are in the jQuery collection. It took no arguments and matched .length. Added in jQuery 1.0, deprecated in 1.8, removed in 3.0.
Use the .length property: $('li').length. It works in every jQuery version, including 3.x and 4.x, and avoids a function-call overhead.
jQuery preferred .length because it is a property, not a method. Keeping both was redundant. Deprecated in 1.8; gone in 3.0.
No. .size is undefined, so calling .size() throws a TypeError. Replace every .size() with .length before upgrading.
0. For example $('#missing').length is 0 on all versions (and .size() was 0 on 1.x/2.x).
Only what is in the current matched set. Descendants are counted only if your selector or chain included them.