An Integer property: how many elements are currently matched in the jQuery object. Added in jQuery 1.0. It is a property — not a method — so write $("div").length, not $("div").length().
Remember
$("div").length // Integer — count of matched elements
// Official idea: count, then grow the set
var n = $("div").length;
$("span").text("There are " + n + " divs.");
// Empty selection → 0 (no error)
// Prefer .length over removed .size()
Select elements, then read the count on that collection.
Build a jQuery set: $("div"), $(".item"), or a chain.
Read .length (no parentheses).
Use the Integer in a message, guard, or comparison.
After .filter() / .add(), read .length again — it reflects the new set.
Never call removed .size() in jQuery 3.x.
Piece
Required?
Role
jQuery collection
Yes
Result of $() or a chain
.length
—
Integer count of matched elements
Arguments
N/A
Property — not a function
Empty set
—
Returns 0, no throw
Pseudocode
Pseudocode
set = $("div")
n = set.length // how many matched
if n === 0:
nothing matched — skip work
else:
update UI or loop with .each()
// After change:
set2 = set.filter(".active")
n2 = set2.length // only the filtered count
// Official demo pattern:
on click:
append a new div
n = $("div").length
show "There are " + n + " divs."
Else. Show a clear “none” message when count is 0.
Edge Cases & Pitfalls
Watch for these when using .length.
property
Not a method
Write $("div").length, not $("div").length().
removed
.size() is gone in jQuery 3
Calling .size() throws. Migrate every call to .length.
scope
Selector scope matters
$("div").length counts the whole document — scope to a container when you need a local total.
chain
Count the set you have
After .filter() or .find(), .length is for that new collection, not the previous one.
Compatibility
Browser Support
.length is a jQuery collection property available since 1.0. It works in every jQuery 1.x / 2.x / 3.x build. Prefer it over removed .size() in jQuery 3.0+.
✓ Stable · jQuery 1.0+
.length
Universal across jQuery 1.x–3.x. Read the Integer on any collection. Pair with .filter() and .each() for common match-count patterns.
100%With jQuery 1.0+
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
.lengthjQuery 1.0+
Bottom line: Safe for production. Empty sets return 0. Replace any leftover .size() calls with .length.
Analysis
Performance Notes
Approach
Cost
Best for
Read .length
Free
Already-built collections
.length vs .size()
Cheaper
Property read — no function call
Re-select every time
Can add up
Cache var $els = … then read $els.length
The property itself is free. Cost comes from re-running expensive selectors — select once, then read .length.
Remember
Key Takeaways
Role: Integer — how many elements are in this set.
One line:.length answers “how many elements did this selection match?”
Frequently Asked Questions
.length is a Number on every jQuery collection. It returns how many DOM elements are currently in the set — for example $("li").length might return 5. Added in jQuery 1.0 and still supported in jQuery 3.x.
It returns 0. jQuery does not throw for empty selections — $("#missing").length is 0. Use if ($(".item").length) as a common guard before loops or updates.
Yes — they returned the same integer. .size() was deprecated in jQuery 1.8 and removed in jQuery 3.0. Always use .length in modern code. .length also avoids the overhead of a function call.
Yes. .length always reflects the current collection. $(".tag").filter(".active").length counts only the filtered subset.
Same idea — a numeric count — but jQuery .length counts DOM elements in the collection. jQuery objects are array-like: index [0] for the first element and read .length for the total.
Use .length for a quick check: if ($(".warn").length) { … }. Use .each() when you need to visit every matched element. Checking .length first avoids unnecessary work on empty sets.