hidden selector
Description: Selects all elements that are hidden.
jQuery(':hidden')
version added: 1.0
Elements can be considered hidden for several reasons:
- They have a CSS
displayvalue ofnone. - 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 at 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).
Examples
Shows all hidden divs and counts hidden inputs.
// in some browsers :hidden includes head, title, script, etc...
// so limit to body
$("span:first").text("Found " +
$(":hidden", document.body).length +
" hidden elements total.");
$("div:hidden").show(3000);
$("span:last").text("Found " + $("input:hidden").length +
" hidden inputs.");
Full source:
<!DOCTYPE html> <html> <head> <script src="http://code.jquery.com/jquery-latest.js"></script> <script> $(document).ready(function(){ // in some browsers :hidden includes head, title, script, etc... // so limit to body $("span:first").text("Found " + $(":hidden", document.body).length + " hidden elements total."); $("div:hidden").show(3000); $("span:last").text("Found " + $("input:hidden").length + " hidden inputs."); }); </script> <style> div { width:70px; height:40px; background:#ee77ff; margin:5px; float:left; } span { display:block; clear:left; color:red; } .starthidden { display:none; } </style> </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> </body> </html>
Was this information helpful?

