:hidden Selector in JQuery



version added: 1.0jQuery(‘:hidden’)

Elements can be considered hidden for several reasons:

  • They have a display value of none.
  • They are form elements with type=”hidden”.
  • Their width and height are explicitly set to 0.
  • An ancestor element is hidden, so the element is not shown on the page.

How :hidden is determined was changed in jQuery 1.3.2. An element is assumed to be hidden if it or any of its parents consumes no space in the document. CSS visibility isn’t taken into account (therefore $(elem).css('visibiity','hidden').is(':hidden') == false). The release notes outline the changes in more detail.


Shows all hidden divs and counts hidden inputs.

<!DOCTYPE html>
  div { width:70px; height:40px; background:#ee77ff; margin:5px; float:left; }
  span { display:block; clear:left; color:red; }
  .starthidden { display:none; }
  <script src="/scripts/jquery-1.4.js"></script>
  <div style="display:none;">Hider!</div>

  <div class="starthidden">Hider!</div>
    <input type="hidden" />

    <input type="hidden" />
    <input type="hidden" />

    // in some browsers :hidden includes head, title, script, etc... so limit to body
    $("span:first").text("Found " + $(":hidden", document.body).length + 
                         " hidden elements total.");
    $("span:last").text("Found " + $("input:hidden").length + " hidden inputs.");


Leave a Reply

Your email address will not be published. Required fields are marked *