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) Making Changes to the DOM Removing an Element from the DOM

James Matthews
James Matthews
21,610 Points

Removing an Element from the DOM task 3/3

I'm causing an error but I don't quite know what it is :/

index.html
<!DOCTYPE html>
<html>
    <head>
        <title>DOM Manipulation</title>
    </head>
    <link rel="stylesheet" href="style.css" />
    <body>
        <ul>
            <li id="first">First Item</li>
            <li id="second">Second Item</li>
            <li id="third">Third Item</li>
        </ul>
        <script src="app.js"></script>
    </body>
</html>
app.js
let myList = document.getElementsByTagName('ul')[0];

let firstListItem = document.querySelector('li:first-child');

firstListItem.removeChild(li);

1 Answer

Steven Parker
Steven Parker
231,271 Points

:point_right: The calling format for removeChild is parent.removeChild(child);.

Conveniently, in task 1 you identified the parent element, and in task 2 you identified the child. So in task 3, you just need to construct the call by filling in the other variables in the right places.

James Matthews
James Matthews
21,610 Points

Ah yes, of course, Thanks Steven!

Steven Parker
Steven Parker
231,271 Points

Hey, James Matthews — did you accidentally hit the wrong button, or was I the victim of a "drive-by downvoting"?

James Matthews
James Matthews
21,610 Points

Hello Steven, I can assure you I did not down-vote, and marked as best answer, so I assume you were indeed a victim! I have given you a +1 though, just to counter it ;)

Steven Parker
Steven Parker
231,271 Points

I wasn't concerned about the point, just wondered if it was an error. But thanks!