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.

JavaScript jQuery Basics Understanding jQuery Events and DOM Traversal DOM Traversal with jQuery

gladys padilla
gladys padilla
7,909 Points

Can someone please help?

I've tried so many ways to solve this and now I'm going crazy! I've tried: prev(), prev().prev(),prev('li') and nothing! Could someone please explain? Thanks!

index.html
<!DOCTYPE html>
<html lang="en">
<head>
    <title>Document</title>
</head>
<body>
  <h2>Student List</h2>

  <ul class="student-list">
    <li>James McAvoy</li>
    <li>Alena Holligan</li>
    <li>Wade Christensen</li>
    <li>Matt Krzyzynski</li>
  </ul>

  <script src="jquery-3.2.1.min.js"></script>
  <script src="app.js"></script>
</body>
</html>
app.js
$('li').eq(2).css('Wade Christensen');
$('li').eq(2).prev('li').prev('li');

2 Answers

Hi Gladys, it seems you were adding some extra code. To get to Wade, all you need to put is:

$('li').eq(2);

And when chaining, you would do the following:

$('li').eq(2).prev().prev();

I hope this helps!

gladys padilla
gladys padilla
7,909 Points

It worked! Thank you so much!!