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

Fabian Pijpers
Fabian Pijpers
Pro Student 34,564 Points

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.

<!DOCTYPE html>
<html lang="en">
  <h2>Student List</h2>

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

  <script src="jquery-3.2.1.min.js"></script>
  <script src="app.js"></script>

2 Answers

Jennifer Nordell
Jennifer Nordell
Treehouse Staff

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:

Fabian Pijpers
Fabian Pijpers
Pro Student 34,564 Points

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.