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

Code Chlallenge "JQuery to select elements"

In the video Andrew said that any valid css selector can be used in jQuery, so why I need to write ul.nav li? In css I could write just .nav li and it would work.. I spent some time figuring out what should I write in that code challenge and didnt understand why .nav li isnt working .. So there is a bug?

1 Answer

The task states select all list items (li) in an unordered list (ul) with the class of 'nav'

So you are basically selecting against this HTML ...

<ul class="nav">
  <li></li>
</ul>

If you use .nav li it would select match against the the example markup above however it would also match against

<div class="nav">
  <ul>
    <li></li>
  </ul>
</div>

So the goal with all selectors (in both CSS & JQuery) is to write them as specific as needed but no more so.