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
Ben Os
20,008 PointsStuck in this Javascript excersize (dom element tracing)
Remove the removeMe element from the parent element.
https://teamtreehouse.com/library/javascript-and-the-dom-2/traversing-the-dom/parent-traversal
This is my answer:
const removeMe = document.querySelector('.remove_me');
let parent = removeMe.parentNode;
parent.removeChild(li);
I want to remove the child of the parent (holded by the parent variable) but it won't be removed... I get "task 1 no longer passing".
2 Answers
Jonathan Grieve
Treehouse Moderator 91,254 PointsHi there,
the biggest problem I can see is that you're trying to pass in a variable that doesn't exist.
Try passing in the const variable removeMe, instead.! :-)
Sebastian H
19,905 PointsHey Ben,
The problem with your code is with your last line:
parent.removeChild(li);
You are passing in 'li' to the removeChild method but this method will not query the DOM to find an 'li'. You have to find the li first, assign the result to a variable and then give this value to the removeChild method.
The good news is you already did this! This is exactly what your 'removeMe' const is. Try using the removeMe const in the removeChild method because it has already properly queried the DOM and selected the correct element.
const removeMe = document.querySelector('.remove_me');
let parent = removeMe.parentNode;
parent.removeChild(removeMe);
Have fun!
Sebastian H
19,905 PointsSebastian H
19,905 PointsHaha I should have refreshed my page before I wrote my verbose answer ??