jQuery API

:visible Selector

visible selector

version added: 1.0jQuery(':visible')

Description: Selects all elements that are visible.

Elements are considered visible if they consume space in the document. Visible elements have a width or height that is greater than zero.

Elements with visibility: hidden or opacity: 0 are considered visible, since they still consume space in the layout. During animations that hide an element, the element is considered to be visible until the end of the animation. During animations to show an element, the element is considered to be visible at the start at the animation.

How :visible is calculated was changed in jQuery 1.3.2. The release notes outline the changes in more detail.

Additional Notes:

  • Because :visible is a jQuery extension and not part of the CSS specification, queries using :visible cannot take advantage of the performance boost provided by the native DOM querySelectorAll() method. To achieve the best performance when using :visible to select elements, first select the elements using a pure CSS selector, then use .filter(":visible").

Example:

Make all visible divs turn yellow on click.

<!DOCTYPE html>
<html>
<head>
  <style>
  div { width:50px; height:40px; margin:5px; border:3px outset green; float:left; }
  .starthidden { display:none; }
  </style>
  <script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
  <button>Show hidden to see they don't change</button>
  <div></div>
  <div class="starthidden"></div>
  <div></div>

  <div></div>
  <div style="display:none;"></div>
<script>
    $("div:visible").click(function () {
      $(this).css("background", "yellow");
    });
    $("button").click(function () {
      $("div:hidden").show("fast");
    });

</script>

</body>
</html>

Demo:

Support and Contributions

Need help with :visible Selector or have a question about it? Visit the jQuery Forum or the #jquery channel on irc.freenode.net.

Think you've discovered a jQuery bug related to :visible Selector? Report it to the jQuery core team.

Found a problem with this documentation? Report it on the GitHub issue tracker

  • http://twitter.com/atrophic Caleb Harrelson

    Note that items currently animating their visibility to hidden (such as with .hide() or .slideUp() ) will still show as visible until the animation has completed.

  • Michel

    Useful if you need to know if a specific object is visible:

    if ( $(‘#myitem’).is(‘:visible’)){

    // perform logic if the item is visible..
    }

  • peegee

    for some reason the (“:visible”) is not working in IE compatibility mode, but (“:hidden”) works

  • Amyfletcher10

    Is this description correct? It looks like the same one for :hidden.

  • Sean

    $(':visible') will select elements that are not shown in the current viewport

  • Guest

    I am implementing table sorting and for performance reasons have detached the table from the dom. However, during the re-coloring of the rows (have to support ie7) I want to ignore hidden rows (table can be filtered). There seems to be no slick way of doing this anymore. I have to walk the array and check the 'display' attribute of each row.