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

Why did we write .length?

.

1 Answer

Christopher Gardner
Christopher Gardner
12,719 Points

Hi Amandeep, it looks like it's running through the pdfs in the list, and using jQuery's :checked selector, you're searching to see if any of the boxes are checked. So it's saying if the length of the number of boxes checked is 0, then prevent downloads from happening. If the checkbox is selected, the length will return 1, allowing for the pdfs to be downloaded.

Hope this helps!

.

Christopher Gardner
Christopher Gardner
12,719 Points

Amandeep Pasricha, you're essentially selecting all of the checkboxes that are checked, which you can then use length on. For example, think about it as if you were using document.querySelectorAll('li'). You've selected all the list items, and can then apply .length on them. It's the same for :checked. You've just selected all the checked checkboxes.