jQuery :hidden Selector

Beginner
5 min read
Updated: Nov 2026
3 examples
Selectors

Definition

:hidden (since jQuery 1.0) selects elements that are hidden — they consume no space in the layout. Opposite of :visible.

Syntax

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

jQuery
$(":hidden")                    // all hidden elements
$("div:hidden")                 // hidden divs only
$("input:hidden")               // hidden inputs (type=hidden, etc.)
$("#panel *").filter(":hidden") // faster scoped pattern

// Counts as hidden:
// · display: none
// · input type="hidden"
// · width/height set to 0
// · a hidden ancestor
//
// NOT hidden (still take space):
// · visibility: hidden
// · opacity: 0
CallWhat it does
:hiddenMatch elements with no layout space
Base selectorLimit type — e.g. div:hidden
.filter(":hidden")Recommended performance pattern
Return valuejQuery set of hidden elements

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

Parameters

ParameterDescription
":hidden"Used in .filter(":hidden"). Recommended performance pattern

Return Value

Return ValueDescription
See examplesCheck the examples below for what this API returns in common cases.

jQuery Examples

Example 1 — Count Hidden Elements and Show Divs

Official idea: tally hidden nodes, reveal hidden divs, count hidden inputs.

jQuery
var hiddenElements = $("body").find(":hidden").not("script");
$("#log").text("Found " + hiddenElements.length + " hidden elements.");
$("div:hidden").show();
$("#inputs").text("Hidden inputs: " + $("input:hidden").length);
Try It Yourself

How It Works

  1. Find. Scan body for :hidden matches.
  2. Exclude. .not("script") drops script nodes from the count.
  3. Show. $("div:hidden").show() reveals only hidden divs.

Example 2 — display:none vs visibility / opacity

Only no-space elements match. Invisible-but-spaced ones do not.

jQuery
$("#gone").hide();
$("#invisible").css("visibility", "hidden");
$("#transparent").css("opacity", 0);

$("#log").text(
  "display:none → " + $("#gone").is(":hidden") + "\n" +
  "visibility:hidden → " + $("#invisible").is(":hidden") + "\n" +
  "opacity:0 → " + $("#transparent").is(":hidden")
);
Try It Yourself

How It Works

  1. hide(). Sets display:none → no space → :hidden.
  2. visibility. Element still occupies layout → not :hidden.
  3. opacity. Fully transparent but still spaced → not :hidden.

Example 3 — Performance: .filter(":hidden")

Official tip: CSS-select a region first, then filter hidden ones.

jQuery
var count = $("#panel *").filter(":hidden").length;
$("#report").text("Hidden inside #panel: " + count);
Try It Yourself

How It Works

  1. CSS first. $("#panel *") uses a fast native path.
  2. Filter. Keeps only descendants that are :hidden.
  3. Scope. Hidden nodes outside #panel are skipped.

Frequently Asked Questions

:hidden selects elements that are hidden — they consume no space in the document layout. Common cases include display:none, input type="hidden", zero width/height, or a hidden ancestor. Available since jQuery 1.0.
No. Elements with visibility:hidden or opacity:0 still take up layout space, so jQuery treats them as visible. Only elements that consume no layout space match :hidden.
Yes. Every element selected by :hidden is not selected by :visible, and vice versa. They are complementary filters in jQuery.
No. It is a jQuery extension and cannot use native querySelectorAll(). Official docs recommend a CSS scope first, then .filter(":hidden") for better performance.
In some browsers, $("body").find(":hidden") can also match head, title, script, and other non-visible document nodes. The official demo excludes script tags before counting user-facing hidden elements.
Starting with jQuery 3, elements without layout boxes — such as br and empty inline elements — are considered :hidden. This slightly refines how :hidden and :visible divide the DOM.

Next: :visible Selector — Select Visible Elements

Select elements that consume layout space — the opposite of :hidden.

:visible Selector — Select Visible Elements 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.

10 people found this page helpful