jQuery Form Checkbox selector

Description and Syntax

$(":checkbox")

Select all checkbox fields (<input type="checkbox">)

Examples

The following code counts the checkbox count in a form.


<html>
  <head>
    <script src="http://java2s.com/style/jquery-1.8.0.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function(){<!--from  w  ww .j a  v a  2  s.c  o m-->
            alert($(":checkbox").length);

        });
    </script>
  </head>
  <body>
    <body>
        <input type="button" value="Input Button"/>
    
        <input type="checkbox">java2s.com</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>

Click to view the demo





















Home »
  jQuery »
    jQuery Tutorial »




Basics
Selector
DOM
Event
Effect
Utilities