jQuery :visible Selector

Beginner
7 min read
Updated: Oct 2026
5 examples
Live preview

What Is :visible?

:visible (since jQuery 1.0) selects elements that consume space in the document. Official docs: they typically have width or height greater than zero. It is the opposite of :hidden.

Remember
$("div:visible")                 // visible divs (official style)
$(".panel").filter(":visible")   // faster pattern (official tip)

// Still :visible (consume space):
//   visibility: hidden
//   opacity: 0

// Not :visible:
//   display: none
//   <option> elements (always hidden in jQuery)

// Opposite: :hidden
NeedUse
Visible elements$("div:visible")
Hidden elements$("div:hidden")
Best performance$("div").filter(":visible")
Show / hide helpers.show() / .hide()
During animation:animated

How to Use :visible

Scope with a CSS selector first, then filter or bind only the visible matches.

  1. Start with a tag or class: $("div") or $(".card").
  2. Narrow with :visible or .filter(":visible") (preferred).
  3. Remember: visibility:hidden and opacity:0 still match.
  4. Treat display:none (and detached nodes) as not visible.
  5. Re-query after .show() / .hide() if the set must stay current.
PieceRequired?Role
Selector stringYes:visible filter (best after a CSS scope)
Context / classRecommendedLimits how many elements are tested
Return value—jQuery collection of visible matches

Pseudocode

Pseudocode
matches = []
for each element in search context:
    if element is in the document
       and element consumes layout space:
        matches.add(element)

return matches

// Official performance tip:
candidates = CSS_query(…)
return candidates.filter(isVisible)

Cheat Sheet

Keep these facts handy while testing visibility.

TopicDetail
Syntax$("elem:visible")
SincejQuery 1.0 · jQuery extension
MeansConsumes layout space
Opposite:hidden
visibility:hiddenStill :visible
opacity: 0Still :visible
display: noneNot visible
<option>Always hidden in jQuery
Performance.filter(":visible") after CSS

Live Preview

Toggle panels, then count div:visible vs div:hidden in this mini demo.

Panel A
Panel B
Panel C (starts hidden)

Same idea as the official demo: only elements that currently take layout space match :visible.

Result
div:visible → 2
div:hidden → 1

/* Panel C is hidden */

jQuery Examples

Short, copy-ready snippets. Open DevTools Console with jQuery loaded, or use Try It Yourself for a live editor.

Example 1 — Official Demo: Click div:visible

Only currently visible divs get the click handler (jQuery API idea).

jQuery
$("div:visible").on("click", function () {
  $(this).text($(this).text() + " ✓");
});
$("#showHidden").on("click", function () {
  $("div:hidden").show();
});
Try It Yourself

How It Works

  1. Select. div:visible finds divs that take layout space now.
  2. Bind. Only those divs receive the click handler.
  3. Reveal. $("div:hidden").show() brings hidden divs into view.
  4. Note. Handlers bound earlier do not auto-attach to newly shown divs unless you re-bind or use delegation.

Example 2 — :visible vs :hidden

The two selectors partition the set — no overlap.

jQuery
function report() {
  $("#out").text(
    "visible: " + $("#boxes div:visible").length + "\\n" +
    "hidden: " + $("#boxes div:hidden").length
  );
}
report();
$("#toggle").on("click", function () {
  $("#c").toggle();
  report();
});
Try It Yourself

How It Works

  1. Visible. Counts elements that consume space.
  2. Hidden. Counts the complementary set.
  3. Toggle. Showing/hiding moves an element from one set to the other.
  4. Rule. An element is never both :visible and :hidden.

Example 3 — opacity:0 Is Still :visible

Official docs — invisible to the eye can still match if layout space remains.

jQuery
$("#ghost").css("opacity", 0);
$("#gone").hide();
console.log("ghost :visible?", $("#ghost").is(":visible"));
console.log("gone :visible?", $("#gone").is(":visible"));
Try It Yourself

How It Works

  1. Opacity. Setting opacity to 0 does not remove the layout box.
  2. Still visible. jQuery therefore reports :visible as true.
  3. Display none. Removes layout space → not :visible.
  4. Same idea. visibility:hidden behaves like opacity here.

Example 4 — Official Performance Pattern: .filter(":visible")

Select with CSS first, then filter visibility.

jQuery
var $open = $(".card").filter(":visible");
$("#out").text("Visible cards: " + $open.length);
Try It Yourself

How It Works

  1. CSS first. $(".card") can use native querySelectorAll.
  2. Filter. .filter(":visible") keeps only layout-visible cards.
  3. Same result. Equivalent to $(".card:visible"), often cheaper.
  4. Why. Official docs recommend this because :visible is not CSS.

Example 5 — Count Visible Panels

Report how many panels are open after each toggle.

jQuery
function update() {
  $("#out").text($(".panel:visible").length + " panel(s) visible");
}
update();
$(".panel").on("click", function () {
  $(this).hide();
  update();
});
$("#reset").on("click", function () {
  $(".panel").show();
  update();
});
Try It Yourself

How It Works

  1. Count. $(".panel:visible").length is the open panel total.
  2. Hide on click. Each click removes one from the visible set.
  3. Update. Re-run the count after every change.
  4. Reset. .show() restores every panel to visible.

Edge Cases & Pitfalls

Check these before relying on :visible in real UIs.

eye vs layout

opacity:0 is still visible

Official docs: visibility:hidden and opacity:0 match :visible because they still take space.

option

<option> is never :visible

All options are treated as hidden. Use :selected for dropdown choices.

perf

Can force layout / reflow

Heavy use may re-render before visibility is known. Prefer classes or .filter(":visible") after a CSS query.

animation

During hide/show animations

While hiding, the element stays :visible until the animation ends; while showing, it is visible from the start.

Browser Support

The :visible pseudo-class is a jQuery extension and has worked since jQuery 1.0. Visibility tests run through jQuery’s engine; use scoped .filter(":visible") or state classes when performance is critical. jQuery 3 refined zero-size layout boxes.

✓ jQuery 1.0+ · extension

jQuery :visible Selector

Supported across jQuery 1.x, 2.x, and 3.x. Prefer .filter(":visible") after a CSS selector for better performance.

100% jQuery visibility selector
Google Chrome All versions · Desktop & Mobile
Full support
Mozilla Firefox All versions · Desktop & Mobile
Full support
Apple Safari All versions · macOS & iOS
Full support
Microsoft Edge All versions · Chromium & Legacy
Full support
Internet Explorer IE 6+ · Legacy environments
Full support
Opera All modern versions
Full support
:visible Universal

Bottom line: Safe everywhere jQuery runs. Remember layout-space rules, avoid bare scans on large DOMs, and pair with :hidden for the complementary set.

Performance Notes

ApproachCostBest for
$("div").filter(":visible")BestOfficial recommended pattern
$(".panel:visible")OKSmall scoped sets
Visibility classOften cheaperFrequent checks in apps
$(":visible")ExpensiveAvoid — tests the whole document

Official docs: :visible cannot use querySelectorAll, and heavy use may force layout. Prefer CSS scoping plus .filter(":visible"), or track open/closed state with a class.

Key Takeaways

  • Role: match elements that consume layout space.
  • Not eye-based: opacity:0 / visibility:hidden still match.
  • Opposite: pair with :hidden.
  • Speed: $("…").filter(":visible"); next is :lang().

One line: $(":visible") means “takes layout space,” not “you can see it” — scope first, then filter.

Frequently Asked Questions

:visible selects elements that consume space in the document layout. Visible elements typically have a width or height greater than zero (jQuery 3 also includes elements with any layout box). Available since jQuery 1.0. It is the opposite of :hidden.
Yes. Official docs: elements with visibility:hidden or opacity:0 still consume layout space, so jQuery treats them as :visible.
Yes. Every element selected by :visible is not selected by :hidden, and vice versa.
No. Official docs: all option elements are considered hidden, regardless of selected state. Use :selected for dropdown options.
No. It is a jQuery extension and cannot use querySelectorAll. Official tip: select with a CSS selector first, then .filter(":visible").
Starting with jQuery 3, elements with any layout boxes — including br and empty inline elements with zero width/height — can match :visible.

Next: :lang() Selector

Learn how to select elements by language with the :lang() selector.

:lang() tutorial →

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