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

I have a problem with jquery challenge 2 of 2 '$('li').eq(2).prev(-2);'

Why does it not work?

$('li').eq(2).prev(-2); As you can see i have correctly called the .prev selector after the .eq() selector. Does anybody see where i went wrong.

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).prev(-2);

2 Answers

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there, Fabian Pijpers ! Looks like you're doing terrific and you clearly have the hang of the eq() method. But in contrast to that method, the prev() does not take an index or positional argument like you've passed. You can however, pass in a selector. The easiest way to move two up here is to run the .prev() twice with no arguments.

I think you can get it with this hint, but let me know if you're still stuck! :sparkles:

Thanks Jennifer for noting that, at least now i can look further without repeating that perticular mistake. At least you tought me not to use indexing at the .prev() method again. Again Thank you.