Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

HTML Build an Interactive Website Introduction to jQuery Using jQuery to Select Elements

jquery for li in ul in class nav

$(".nav ul li"); whats the correct answer?

3 Answers

Maximiliane Quel
PLUS
Maximiliane Quel
Courses Plus Student 55,489 Points

you want to chose the unordered list with the class of nav = ul.nav and within that restriction the list items:

$('ul.nav li');
Eric Martz
Eric Martz
16,007 Points

Ack, I must have hit reply and started putting together an answer while you were posting your answer. Didn't mean to post right after you. Sorry for the duplication.

Maximiliane Quel
Maximiliane Quel
Courses Plus Student 55,489 Points

no worries. at least we are not contradicting each other ;0). site seems to be quite sluggish today, which doesn't help

Eric Martz
Eric Martz
16,007 Points

When selecting an element with a class name, you have to put it together. So all ul elements with the class nav would be ul.nav.

To get the li elements inside the ul with class nav just add it to the end: ul.nav li.

$('ul.nav li')

Thanks Eric and Maximiliane for quick reply!!!