How to count checked checkboxes using jquery

    To count checked checkboxes using jquer use following code for example
    <ul class="departments">
    <li><label>Drupal Development<input type="checkbox" name="department[]" /> </label></li>
    <li><label>Wordpress Development<input type="checkbox" name="department[]" /></label></li>
    <li><label>Joomla Development<input type="checkbox" name="department[]" /></label></li>
    <li><label>Jquery Development<input type="checkbox" name="department[]" /></label></li>
    <li><input type="submit" name="count" value="count" id="edit-count" /></li>
    </ul>

    Jquery code to count checked elementson clicking count button

    <script type="text/javascript">
    $(document).ready(function() {
    $('#edit-count').click(function() {
      var count = $('.departments input:checked').length;
      alert(count);
    });
    });
    </script>
    5
    Average: 5 (1 vote)

    User login