The all selector — written as "*" — matches every element in the current search context. It is the CSS universal selector, available since jQuery 1.0. Use it for demos and diagnostics; scope it for safer real-world use.
Remember
$("*") → every element in the document
$("#panel").find("*") → every descendant inside #panel
$("body *") → every descendant of body (not body itself)
$("*").length → count matches
prefer $(".item") / $("#id") in production
Pass "*" to $(), optionally narrow the root, then read .length or chain a method.
Decide the context — whole document, body, or a specific container.
Call $("*") or $("#id").find("*").
Use .length to count, or chain .css() / .each() on the set.
On large pages, avoid global $("*") — scope first or pick a specific selector.
Piece
Required?
Role
"*"
Yes
Universal selector string
Context / .find()
Optional
Limits which subtree is searched
.length
Optional
Numeric count of matched elements
Pseudocode
Pseudocode
root = document (or a container element)
matches = empty list
for each element in root tree:
if element is an element node:
add element to matches
return jQuery(matches)
// then: .length | .css(...) | .each(...)
Reference
Cheat Sheet
Keep these facts handy while using "*".
Topic
Detail
Syntax
$("*") / jQuery("*")
Scoped
$("#id").find("*")
Body only
$("body *") (excludes <body> itself)
Count
$("*").length
Nodes matched
Elements only — not text or comments
Official caution
Slow except when used alone on small trees
Since
jQuery 1.0 (CSS1 universal selector)
Try it
Live Preview
Compare how many elements match under different roots against a tiny sample DOM.
Sample markup mirrors the official jQuery all-selector demos (scoped under a container).
Skip styling. You do not need .css() just to count nodes.
Global count.$("*").length covers the whole document.
Scoped count..find("*").length covers one panel only.
Compare. The gap shows how much scoping reduces the match set.
Example 4 — $("*") vs $("body *")
Limit to body descendants to skip head-only tags like title and meta.
jQuery
console.log("All nodes:", $("*").length);
console.log("Body descendants:", $("body *").length);
// body * does NOT include <body> itself — only children and below
Avoid collect-then-filter.$("*").filter(...) still visits every element first.
Target directly.$("#test button") lets the engine skip unrelated nodes.
Read the text..text() returns the button label for a clear result.
Production habit. Prefer ID, class, or tag selectors whenever you know the target.
Edge Cases & Pitfalls
Check these before using "*" in real projects.
slow
Global $("*") on large DOM
Official docs call it extremely slow except when used alone on small trees. Scope with .find("*") or use a specific selector.
count
Extensions inflate counts
Add-ons that inject nodes can raise $("*").length. Treat global counts as approximate.
filter
$("*").filter(...) still pays full cost
Filtering after a universal match still collects every element first. Prefer a direct selector.
nodes
Elements only
"*" never matches text or comment nodes. Use DOM APIs if you need those.
Compatibility
Browser Support
The all selector "*" is part of CSS1 and has worked in jQuery since 1.0. Any browser that runs your jQuery version supports it — performance, not compatibility, is the main concern.
Bottom line: Compatibility is not the issue — scope your searches and prefer specific selectors in production. Use $("*") for small demos, diagnostics, or inside a narrow container.
Analysis
Performance Notes
Approach
Cost
Best for
$("#box").find("*")
Subtree size
Every descendant in one region
$(".item") / $("#id")
Targeted lookup
Production UI code
$("*") on full page
Whole document
Demos / audits only
Official guidance: the universal selector is extremely slow except when used by itself. Combining * with other selectors forces more work. Keep the context small, or skip * when a tag, class, or ID will do.
Remember
Key Takeaways
Role:"*" matches every element in the search context.
Scope: prefer $("#id").find("*") over global $("*").
Count: use .length — no loop required.
Production: prefer ID, class, or tag selectors when you know the target.
One line: use "*" for universal matches — but keep the tree small, or pick a specific selector instead.
Frequently Asked Questions
The all selector matches every element node in the search context. $("*") from the document root collects html, head, body, and every descendant into one jQuery object you can chain with .css(), .each(), or .length.
Yes. jQuery uses the same idea as the CSS universal selector. The asterisk matches any element type.
jQuery must visit every element in the context. On a large page that can mean thousands of nodes. The official API warns it is extremely slow except when used by itself on a small tree.
Start from a container: $("#panel").find("*") or $("div.panel *"). Only descendants of that root are matched — fewer nodes and clearer intent.
Yes when searching from the document root. $("body *") skips head-only nodes like title and link, but still includes script tags inside body.
Read .length on the jQuery object: var n = $("#test").find("*").length. It returns a number, not a collection.