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

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
231,271 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
231,271 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
46,427 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
46,427 Points

Steven Parker .. stated this first I see.