JQuery Selector checked

From CoderLearner
Jump to: navigation, search

Description

Matched all checked elements.

Syntax

$(':checked');

Example 1

<html>
   <head>
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
      <title>Select</title>
      <script 
         type="text/javascript" 
         src="/lib/jquery-1.7.2.min.js">				 
      </script>

      <script>
         $().ready(function() {
            $(':checkbox').click(function(){
               var check_total = $('input:checked').length;
               $('span').html('Total Checked: '+check_total);
            })
           
         });
      </script>
   </head>
   <body> 
      <span></span>
      <form>
         <input type="checkbox" name="car0" checked="checked"/>
         <input type="checkbox" name="car1" checked="checked"/>
         <input type="checkbox" name="car2" />
         <input type="checkbox" name="car3" />
       
      </form>
   </body>
</html>

Try It