JavaScript JavaScript and the DOM Traversing the DOM Parent Traversal

handy christian
handy christian
2,899 Points

Please help I'm stuck on the event challenge, help me solve this problem

Help

app.js
const removeMe = document.querySelector('.remove_me');
let parent = removeMe.parentNode;

removeMe.addEventListener('click', (event) => {
                   parent.removeChild('removeMe');     
                        });
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>

3 Answers

Steven Parker
Steven Parker
172,090 Points

Task 2 says "Next, remove the removeMe element from the parent element."

You're pretty close, but I see two issues:

  • You don't need an event listener here, just the code to perform the removal.
  • The argument to "removeChild" should not have quotes around it.
handy christian
handy christian
2,899 Points

hi Steven Parker, i saw your profile you have a lot of javascript points. I just want to know how old are you and what kind of job you get hired right now? I just want to know so i can be motivated to learn more about programming :D

Steven Parker
Steven Parker
172,090 Points

Let's just say "Math.log(my_age) > 4". :wink: When I first started learning about programming, punched cards were a common input medium, and computers took up a whole room.

I was already a software engineer (mostly C/C++) when I learned JavaScript. I do more web-oriented stuff now, which is why Treehouse has been great for expanding my skill set.

handy christian
handy christian
2,899 Points

:,) i hope someday i can be like you tho thanks

G Johnson
G Johnson
44,486 Points

The fix is simple - just remove the quotes around 'removeMe'. Tested on code pen.

No quotes are needed because this is a variable that you set to represent the dom info.

G Johnson
G Johnson
44,486 Points

Steven Parker .. stated this first I see.