jQuery :visible Selector

Beginner
5 min read
Updated: Nov 2026
3 examples
Selectors

Definition

: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.

Syntax

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

jQuery
$("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
CallWhat it does
Selector string:visible filter (best after a CSS scope)
Context / classLimits how many elements are tested
Return valuejQuery collection of visible matches

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

Parameters

ParameterDescription
Step 1Start with a tag or class: $("div") or $(".card").
Step 2Narrow with :visible or .filter(":visible") (preferred).
Step 3Remember: visibility:hidden and opacity:0 still match.

Return Value

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

jQuery Examples

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.

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.

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.

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 — Match by Language

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

:lang() Selector — Match by Language 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