jQuery API

:hidden Selector

hidden selector

version added: 1.0jQuery(':hidden')

Description: Selects all elements that are hidden.

Elements can be considered hidden for several reasons:

  • They have a CSS 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.

Elements with visibility: hidden or opacity: 0 are considered to be 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 of the animation.

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('visibility','hidden').is(':hidden') == false). The release notes outline the changes in more detail.

Additional Notes:

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

Example:

Shows all hidden divs and counts hidden inputs.

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

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

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

  </span>
<script>
// in some browsers :hidden includes head, title, script, etc...
var hiddenEls = $("body").find(":hidden").not("script");

$("span:first").text("Found " + hiddenEls.length + " hidden elements total.");
$("div:hidden").show(3000);
$("span:last").text("Found " + $("input:hidden").length + " hidden inputs.");
</script>

</body>
</html>

Demo:

Support and Contributions

Need help with :hidden 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 :hidden Selector? Report it to the jQuery core team.

Found a problem with this documentation? Report it to the jQuery API team.

* All fields are required
  • livefree75

    After spending a good 8 hours tracking down a related issue, I discovered that $(“:hidden”) matches <OPTION> elements in Internet Explorer, but not Firefox.

    This killed me when I was trying to set all my hidden form elements to “”. In IE, it also set the values of all the option elements to “”, causing extremely undesired behavior. Took me forever to figure it out.

  • livefree75

    Well, any solution would have to consider the definition of $(“:hidden”). I'd like to dig into the code and see why <option> elements are matched in IE but not FF.

  • livefree75

    A workaround would be to do: $(“:hidden”).not(“option”)

  • Euler

    Is there any solution for this?
    Euler S.G.

  • javad

    How can I select elements which are not hidden? I mean opposite to $(‘:hidden’)

  • http://www.learningjquery.com/ Karl Swedberg

    You can use the :visible selector.

  • A. Q.

    why is “6 hidden elements total”? it should be 5, isn't it?

  • pp

    it seems that @An ancestor element is hidden, so the element is not shown on the page.@ is not working properly… I have a 'tr' that is surely hidden on page (with all its inner content), but elements inside it are “not hidden”:(td:hidden).length ==0.

  • Marcjae

    the 'starthidden' class is styled to “display:none”

  • Marcjae

    the 'starthidden' class is styled to “display:none”

  • guest

    lol? u could juz use == false..

  • Brian

    How can you find text that is hidden because of overflow: hidden? :hidden doesn't see them because they are technically visible.

  • Brian

    How can you find text that is hidden because of overflow: hidden? :hidden doesn't see them because they are technically visible.

  • krishna

    the <script></script> in the body is also considered as hidden element.