JavaScript JavaScript and the DOM Traversing the DOM Parent Traversal

On line 2 of app.js, traverse to the parent element of the removeMe element.

On line 2 of app.js, traverse to the parent element of the removeMe element. I have no idea what to do. I have tried everything I am still getting it wrong. What is the code?

app.js
var removeMe = document.querySelector('.remove_me');
var removeChild = removeChild.parentNode('removeChild');
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>

1 Answer

bema konate
bema konate
12,975 Points

Instead of doing: var removeChild = removeChild.parentNode('removeChild'); Do: var removeChild = removeMe.parentNode; And if that don't work: var parent = removeMe.parentNode;

You have to create a new variable and access the parent by using the variable that has the child element stored, not the new variable you created