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

Raedawn Long
Raedawn Long
6,939 Points

Hello, Any suggestions on this question with use of transverse method.

Any suggestions on this question with use of transverse method.

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('li').prev('li');
$('li').eq(2).prev();

1 Answer

Raedawn Long you're almost there, we already have our position chosen in

$('li').eq(2)

now to traverse up we just need to go up 2 times with prev() method, no need to add the filter parameter.

$('li').eq(2).prev().prev()