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

Thomas H
seal-mask
.a{fill-rule:evenodd;}techdegree
Thomas H
Full Stack JavaScript Techdegree Student 4,545 Points

Parent Transversal

Hi everybody,

I don't find the way to solve the second task, i used the removeChild method but it doesnt work, someone have a hint ?

Thank you

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

4 Answers

sorry about that. your code its almost correct but when you remove an element is the variable name. and you are using a string.

parent.removeChild('removeMe');  // this is a string

it should be

parent.removeChild(removeMe); // with no quotations marks
Thomas H
seal-mask
.a{fill-rule:evenodd;}techdegree
Thomas H
Full Stack JavaScript Techdegree Student 4,545 Points

I found the solution :)

var removeMe = document.querySelector('.remove_me'); var parent = removeMe.parentNode; parent.removeChild(removeMe);

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

if you read the question again, it doesn't say anything about removing the element..

just remove this

parent.removeChild('removeMe');

and you should be fine

Thomas H
seal-mask
.a{fill-rule:evenodd;}techdegree
Thomas H
Full Stack JavaScript Techdegree Student 4,545 Points

Thank you but actually my question is about the second task "Next, remove the removeMe element from the parent element." ;)