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 trialFabian Pijpers
Courses Plus Student 41,372 PointsI 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.
<!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>
$('li').eq(2).prev(-2);
2 Answers
Jennifer Nordell
Treehouse TeacherHi 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!
Fabian Pijpers
Courses Plus Student 41,372 PointsThanks 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.