javascript - How do I count how many checkboxes are selected on a page with jQuery -


i want count how many checkboxes on page selected using jquery. i've written following code:

      var numberofcheckboxesselected = 0;       $(':checkbox').each(function(checkbox) {           if (checkbox.attr('checked'))               numberofcheckboxesselected++;       }); 

however, code errors out message "object doesn't support property or method" on third line.

how count how many checkboxes selected on page?

jquery supports :checked pseudo-selector.

var n = $("input:checked").length; 

this work radio buttons checkboxes. if want checkboxes, have radio buttons on page:

var n = $("input:checkbox:checked").length; 

Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -