jQuery :visible Selector

Beginner
⏱️ 9 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
jQuery extension · jQuery 1.0+

What You’ll Learn

The :visible selector matches elements that consume layout space in the document — width or height greater than zero (jQuery 3+ includes any layout box). jQuery extension since 1.0; opposite of :hidden.

01

Syntax

:visible

02

Layout

Uses space

03

Official

Click & reveal

04

:hidden

Opposite

05

Still visible

opacity, visibility

06

.filter()

Performance

Introduction

Attach click handlers only to shown panels, count open tabs, validate what the user can actually see, or style elements that take up space — jQuery’s :visible pseudo-class selects every element that consumes layout space in the document.

jQuery has supported :visible since version 1.0. Official documentation defines visibility by layout boxes, not by whether pixels appear on screen. Because checking visibility can force layout recalculation, prefer scoping with CSS first, then .filter(":visible"), or track state with a class when performance matters.

Understanding the :visible Selector

An element is :visible when it (and its ancestors) consume layout space in the document:

  • Normal block or inline content with size → matches :visible.
  • visibility: hidden or opacity: 0 → still visible to jQuery (uses space).
  • display: none or hidden ancestor → not :visible.
  • input type="hidden" → not :visible.
  • <option> elements → always treated as hidden (never :visible).
💡
Beginner Tip

:visible is about layout boxes, not whether you can see pixels. A transparent or invisible-but-sized element is still :visible.

📝 Syntax

Official jQuery API form (since 1.0):

jQuery
jQuery( ":visible" )

// typical usage:
$( ":visible" )
$( "div:visible" )
$( "tr:visible" )

// official demo pattern:
$( "div:visible" ).on( "click", function () {
  $( this ).css( "background", "yellow" );
});
$( "button" ).on( "click", function () {
  $( "div:hidden" ).show( "fast" );
});

// performance pattern — CSS scope, then filter:
$( "#panel *" ).filter( ":visible" )

Parameters

  • None:visible takes no arguments. jQuery evaluates layout and ancestry.

Return value

  • A jQuery object containing every matched visible element in document order.
  • Empty collection when nothing in scope is visible.

Official jQuery API example

jQuery
$( "div:visible" ).on( "click", function () {
  $( this ).css( "background", "yellow" );
});
$( "button" ).on( "click", function () {
  $( "div:hidden" ).show( "fast" );
});

⚡ Quick Reference

CSS / markup:visible?:hidden?
Normal sized elementYesNo
display: noneNoYes
visibility: hiddenYesNo
opacity: 0YesNo
input type="hidden"NoYes
<option>NoYes

📋 :visible vs :hidden, CSS, and classes

Layout visibility vs pixel visibility vs manual state tracking.

:visible
$("div:visible")

Has layout box

:hidden
$("div:hidden")

Opposite set

:selected
$("option:selected")

Dropdown options

.is-shown
$(".is-shown")

Class (fast)

Examples Gallery

Example 1 follows the official jQuery visible demo. Examples 2–5 cover the :hidden complement, visibility vs display, scoped .filter(":visible"), and binding handlers to visible list items only.

📚 Official jQuery Demo

Click visible divs to highlight them; button reveals hidden divs.

Example 1 — Official Demo: div:visible click + reveal hidden

Official jQuery demo — click any visible div to turn its background yellow; click the button to show hidden divs quickly.

jQuery
$( "div:visible" ).on( "click", function () {
  $( this ).css( "background", "yellow" );
});
$( "button" ).on( "click", function () {
  $( "div:hidden" ).show( "fast" );
});
Try It Yourself

How It Works

Only divs with a layout box match div:visible. Hidden divs with display:none are excluded until the button runs div:hidden + .show().

Example 2 — Complement: count :visible vs :hidden

Inside a container, visible and hidden sets partition every child — counts should add up.

jQuery
var $box = $( "#box" );
var visible = $box.find( ":visible" ).length;
var hidden = $box.find( ":hidden" ).length;
$( "#report" ).text( visible + " visible, " + hidden + " hidden" );
Try It Yourself

How It Works

Official docs: :visible and :hidden are complementary — an element matches exactly one of them.

📈 Practical Patterns

Invisible-but-sized elements, scoped filtering, UI handlers.

Example 3 — display:none vs visibility:hidden

visibility:hidden and opacity:0 still match :visible — only display:none does not.

jQuery
console.log( "display:none →", $( "#gone" ).is( ":visible" ) );
console.log( "visibility:hidden →", $( "#invisible" ).is( ":visible" ) );
console.log( "opacity:0 →", $( "#transparent" ).is( ":visible" ) );
Try It Yourself

How It Works

Official docs: jQuery ignores pixel visibility. Elements that still consume layout space are :visible.

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

Scope to a table body with CSS, then filter visible rows — official performance guidance.

jQuery
var count = $( "#data-table tbody tr" ).filter( ":visible" ).length;
$( "#report" ).text( "Visible rows: " + count );
Try It Yourself

How It Works

Limit the candidate set before running the visibility test — faster than scanning the entire document with bare $(":visible").

Example 5 — UI: bind handlers to li:visible only

Attach click highlights only to list items the user can see — skip collapsed or hidden items.

jQuery
$( "#menu li:visible" ).on( "click", function () {
  $( this ).addClass( "active" );
});
$( "#toggle" ).on( "click", function () {
  $( "#menu .extra" ).toggle();
});
Try It Yourself

How It Works

Combine scoped li:visible with toggles — hidden items stay out of the handler set until shown.

🚀 Common Use Cases

  • Interactive demos$("div:visible").on("click", …) as in the official demo.
  • Reveal hidden UI — pair with $("div:hidden").show() on a button click.
  • Tables & lists — count or style only tr:visible or li:visible rows.
  • Validation — ensure required fields inside visible panels are filled.
  • Tabs & accordions — operate on the open panel with :visible.
  • Performance — scope then .filter(":visible") instead of global scans.

🧠 How jQuery Evaluates :visible

1

Build candidate set

Evaluate prefix — all elements, div:visible, or scoped descendants.

Query
2

Check layout boxes

Test whether the element and ancestors consume space — may trigger layout work.

Layout
3

Apply jQuery rules

Treat visibility/opacity as visible; exclude display:none and hidden ancestors; jQuery 3+ includes layout boxes like br.

Rules
4

Return collection

Complement of :hidden — chain .on(), .css(), or read .length.

📝 Notes

  • Available since jQuery 1.0 — jQuery extension, not native CSS.
  • Opposite of :hidden — partitions the DOM into two sets.
  • visibility:hidden and opacity:0 are :visible.
  • All <option> elements are considered hidden — never :visible.
  • During animations: visible at start of show; hidden until hide animation completes.
  • Heavy use can hurt performance — prefer classes or scoped .filter().
  • jQuery 3+: elements with layout boxes (e.g. br, empty inline) are :visible.

Browser Support

The :visible pseudo-class is a jQuery extension and works in jQuery 1.0+. Visibility tests run through jQuery’s engine consistently across browsers, but may force layout recalculation. Use scoped .filter(":visible") or state classes when performance is critical.

jQuery 1.0+ · extension

jQuery :visible Selector

Layout-based visibility — not the same as CSS pixel visibility.

100% jQuery only
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 Extension

Bottom line: Pair with :hidden — scope first, then filter on large pages.

Conclusion

The :visible selector matches elements that consume layout space — normal content, invisible-but-sized elements, and anything not hidden by display:none or a hidden ancestor. The official demo highlights visible divs on click and reveals hidden ones with a button.

Remember it is the opposite of :hidden, treats visibility/opacity as visible, and prefer scoped .filter(":visible") when performance matters.

💡 Best Practices

✅ Do

  • Scope with $("#panel *").filter(":visible")
  • Pair with :hidden — complementary sets
  • Use div:visible for interactive demos and handlers
  • Re-bind or delegate when toggling visibility often
  • Track UI state with classes when toggling repeatedly

❌ Don’t

  • Assume visibility:hidden excludes :visible
  • Assume opacity:0 excludes :visible
  • Expect option:visible to match dropdown options
  • Run bare $(":visible") on huge DOM trees repeatedly
  • Use :visible in native CSS — jQuery-only extension

Key Takeaways

Knowledge Unlocked

Five things to remember about :visible

Layout boxes, not pixel visibility.

5
Core concepts
:hidden 02

Opposite

Complement

Rule
0 03

opacity

Still visible

CSS
demo 04

Official

Click & reveal

Demo
.filter 05

Scope

Performance

Tip

❓ Frequently Asked Questions

:visible selects elements that consume space in the document layout — typically width or height greater than zero. Available since jQuery 1.0. It is the opposite of :hidden.
Yes. Elements with visibility:hidden or opacity:0 still take up layout space, so jQuery treats them as :visible. Only elements with no layout box match :hidden.
Yes. Every element selected by :visible is not selected by :hidden, and vice versa. Together they partition the DOM into two complementary sets.
No. jQuery considers all option elements hidden, so they never match :visible. Use :selected to work with dropdown options instead.
No. It is a jQuery extension and does not work in native querySelectorAll(). Official docs recommend selecting with a CSS scope first, then .filter(":visible") for better performance.
Starting with jQuery 3, elements that have a layout box — including br tags and empty inline elements — count as :visible even when width and height are zero. This refines how :visible and :hidden divide the DOM.
Did you know?

During show/hide animations, jQuery treats elements as :visible at the start of a show animation and as :hidden until a hide animation completes. That timing affects which elements match during transitions.

Continue to :lang() Selector

After layout visibility with :visible, learn how :lang() matches multilingual content by language code.

:lang() selector 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.

6 people found this page helpful