Reputation: 19713
I have this simple line, that I was hoping would count all checked checkboxes with the class (.photos):
var count = $('.photos').length;
It counts all the checkboxes that have that class (.photos) but it doesn't count the checked ones.
Does anybody know how to alter this line to count the checked checkboxes within this class?
Regards
Upvotes: 0
Views: 93
Reputation: 165961
You can use the :checked
pseudo-selector:
var count = $(".photos:checked").length;
Upvotes: 9
Reputation: 887365
You're looking for the :checked
selector, which will only match checked elements.
Upvotes: 2