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 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!!