.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.
Syntax
Start with these common calls. Keep them short and readable.
jQuery
// 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);
Call
What it does
size()
Learn jQuery .size(): count matched elements (deprecated 1.8, removed 3.0), migrate to .length, empty sets, examples, pitfalls, and FAQs.
Load jQuery before your script (CDN or local file), then wrap DOM work in $(function () { ... }) when needed.
Parameters
Parameter
Description
Step 1
Build a jQuery collection with a selector or chain.
Step 2
Read .length to get the count as a number.
Step 3
Use that number in conditions, labels, or loops.
Return Value
Return Value
Description
jQuery object
Most setters and traversing helpers return the jQuery collection so you can chain more methods.
Value / undefined
Getters usually return a value from the first matched element, or undefined when nothing applies.
.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.