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

What am i doing wrong?

im not understanding if i have to select the first one and hide it as well? And i cant seem to target the first name... i thought it had the number #0?

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

1 Answer

Steven Parker
Steven Parker
173,537 Points

The task 2 instructions say "You've just learned about the next() and prev() methods. Use one of them to traverse from Wade Christensen to James McAvoy in the list of students."

There's no mention of "hide" in the instructions, you only need to do the traversal. Also, the "prev" method does not take an argument (but you can chain more than one of them together).

Steven Parker could you kindly write down the solution for this test please?

Steven Parker
Steven Parker
173,537 Points

I'd feel better about helping you get it yourself, I think you'll have a better learning experience that way.

Give it a shot using the hints I've given you; and if you still have trouble, show your revised code and we can take it from there.

Thanx for not telling me the answer! lol . i figured it out . It was SO EASY im embarrassed lol.. Im doing JS course and this at the same time so doing both gave me some insight .

Steven Parker
Steven Parker
173,537 Points

Obe Juarez — Glad to help. You can mark a question solved by choosing a "best answer".
Happy coding!