Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript jQuery Basics Working with jQuery Collections Stopping the Browser's Default Behavior

The purpose of using $(':checked').length === 0.

I don't quite understand what $(':checked').length === 0. means?

2 Answers

Steven Parker
Steven Parker
231,275 Points

The $ is the abbreviation for jQuery, so this creates a jQuery object by selecting every element that has the status of "checked" (by using the pseudo-class selector). Then it accesses the length of that collection and looks to see if it is equal to 0, meaning the list is empty.

So essentially, it's a conditional expression asking "is there nothing checked on the page?".

Steven Parker
Steven Parker
231,275 Points

No specific tag type is being selected here, but anchors don't have a "checked" attribute so they could not be selected. I believe only input tags (of type="checkbox" or "radio") can have this attribute.

If the question has been answered, you can mark it solved by choosing a "best answer".
And happy coding!

Is the :checked (pseudo-class selector) part relating to the anchor tags?

Steven Parker
Steven Parker
231,275 Points

No, see the comment I added to my answer.

No It's not. The :checked selector matches all elements that are checked or selected, these include checkboxes, radio buttons and option from the select element.