How to get count with a selection like $(".... :checked")?
I need to get a count of checkboxes that are cu开发者_高级运维rrently checked.
How do I do that?
$(".... :checked").count()
doesn't work.
$("input:checked").length;
Try this
$("input:checked").length
$(':checkbox:checked').length
should give you the required count.
Try this instead:
$(":checked").length
Try .length
; for example: $('#some_id input:checked').length
.
try .length or .size() - they are essentially the same thing. Each results in the count of the number of elements in the matched set. Apparently .length is the preferred choice, as it is faster.
You need to use length
.
$("#something:checked").length;
You can always assign a class to the check box elements and select them using the following syntax:
$('input[class="yourCheckBoxClass"]:checked').length;
This will give you the total of check boxes selected.
精彩评论