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 trial

JavaScript JavaScript and the DOM (Retiring) Traversing the DOM Parent Traversal

kingdavid igbayilola
kingdavid igbayilola
8,678 Points

javascript DOM

i am getting confused here with traversal

app.js
const removeMe = document.querySelector('.remove_me');
let parent.addEventListener('click', (event)=> {
  if (event.target.tagName == 'LI') {
    let li = event.target;
  let ul = li.parentNode;
      }
});
index.html
<!DOCTYPE html>
<html>
    <head>
        <title>Parent Traversal</title>
    </head>
    <link rel="stylesheet" href="style.css" />
    <body>
        <ul>
            <li>Hello</li>
            <li>Hi</li>
            <li class="remove_me">Good bye!</li>
            <li>Howdy</li>
        </ul>
        <script src="app.js"></script>
    </body>
</html>

2 Answers

Steven Parker
Steven Parker
231,271 Points

Task 1 says, "On line 2 of app.js, traverse to the parent element of the removeMe element.". This will only involve making an assignment to the "parent" variable. You won't need to establish an event listener, use any conditional code, or create any other variables. And as mentioned in the instructions, only one new line of code will be added.

And when you get to task 2, it also will need only one additional line of code.

You just need to change line 2 only. β€œLet parent = removeMe.parentNode;”