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 trialvamosrope14
14,932 PointsWhy did we write .length?
.
1 Answer
Christopher Gardner
12,719 PointsHi 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!
vamosrope14
14,932 Pointsvamosrope14
14,932 Points.
Christopher Gardner
12,719 PointsChristopher Gardner
12,719 PointsAmandeep 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.