jQuery Selector How to - Select elements that are hidden, or input elements of type "hidden"








Question

We would like to know how to select elements that are hidden, or input elements of type "hidden".

Answer


<!--from w w w  .  j ava  2s .c  om-->
<html>
  <head>
    <script type="text/javascript" src='http://code.jquery.com/jquery-1.5.2.js'></script>
    <script type="text/javascript">
        $(document).ready(function(){
            console.log($(":hidden").length);
        });
    </script>
  </head>
  <body>
    <body>
        <input type="button" value="Input Button"/>
        <input type="checkbox">asdf</input>
        <input type="checkbox" />
        <input type="checkbox" />
        <input type="file" />
        <input type="hidden" />
        <input type="image" />
        <input type="password" />
        <input type="radio" />
        <input type="reset" />
        <input type="submit" />
        <input type="text" />
    
        <select><option>Option<option/></select>
        <textarea></textarea>
        <button>Button</button>
    </body>
</html>

The code above is rendered as follows: