So I was asked a simple question on Treehouse, but I'm confused about how to order the code.
I was asked to use jQuery to select all list items in an unordered list with the class of 'nav'. I'm not sure how to order my code (I'm literally brand new to JQuery). Here's my incorrect answer.
$("li ul .nav");
The following selects all list items in a list that has the .nav class (<ul class="nav">...</ul>
):
$("ul.nav li");
Try this:
$('ul.nav li');
This selects every child li in ul with the class 'nav'.
Ancestor elements need to be first, as jQuery looks "down" from the <html>
element, and to select ul
's with a class .nav
you need to do ul.nav
.
$('ul.nav li');