0

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

2 Answers 2

9

You can use the :checked pseudo-selector:

var count = $(".photos:checked").length;
Sign up to request clarification or add additional context in comments.

2 Comments

oh, that easy!! I was try all sorts of things apart from that! Thanks for your time
Yep, that easy! As with most things in jQuery, there's a nice quick way of doing it. Glad I could help.
2

You're looking for the :checked selector, which will only match checked elements.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.