jQuery Form How to - Select all input elements of type checkbox








Question

We would like to know how to select all input elements of type checkbox.

Answer


<!--from   w w w.  j  ava  2  s . c o m-->
<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($(":checkbox").length);

        });
    </script>
  </head>
  <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: