jQuery All Selector “*”

Beginner
5 min read
Updated: Nov 2026
3 examples
Selectors

Definition

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.

Syntax

Start with these common calls. Keep them short and readable.

jQuery
$("*")                    → 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
CallWhat it does
"*"Universal selector string
Context / .find()Limits which subtree is searched
.lengthNumeric count of matched elements

Load jQuery before your script (CDN or local file), then wrap DOM work in $(function () { ... }) when needed.

Parameters

ParameterDescription
Step 1Decide the context — whole document, body, or a specific container.
Step 2Call $("*") or $("#id").find("*").
Step 3Use .length to count, or chain .css() / .each() on the set.

Return Value

Return ValueDescription
jQuery objectMost setters and traversing helpers return the jQuery collection so you can chain more methods.
Value / undefinedGetters usually return a value from the first matched element, or undefined when nothing applies.

jQuery Examples

Example 1 — Count Every Element in the Document

Official idea: $("*") matches the whole document. Read .length to see how many elements exist.

jQuery
var elementCount = $("*").length;
console.log(elementCount + " elements found");
Try It Yourself

How It Works

  1. Run the universal selector. $("*") collects every element from the document root.
  2. Read the count. .length returns how many nodes matched — no loop needed.
  3. Expect a large number. Real pages include head tags, scripts, and chrome.

Example 2 — Find All Elements Inside #test

Official scoped pattern: exclude the rest of the page with .find("*").

jQuery
var tags = $("#test").find("*").map(function () {
  return this.tagName;
}).get().join(", ");

console.log(tags);
console.log("count:", $("#test").find("*").length);
Try It Yourself

How It Works

  1. Pick a root. $("#test") selects one container.
  2. Walk descendants. .find("*") matches every element inside it — not #test itself.
  3. List tag names. .map() prints a clear sequence for learning.

Example 3 — Count Without Changing Styles

Compare document-wide vs panel counts using .length alone.

jQuery
var totalInPage = $("*").length;
var totalInPanel = $("#test").find("*").length;

console.log("Document:", totalInPage);
console.log("#test panel:", totalInPanel);
Try It Yourself

How It Works

  1. Skip styling. You do not need .css() just to count nodes.
  2. Global count. $("*").length covers the whole document.
  3. Scoped count. .find("*").length covers one panel only.

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.

Next: Element Selector ("element")

Learn how to select elements that are mid-animation with jQuery effects.

Element Selector ("element") tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

9 people found this page helpful