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 trialShreemangal Sethi
Full Stack JavaScript Techdegree Student 15,552 PointsNot able to understand how to remove the list item element stored in firstListItem from the DOM.
When it says list item element does it mean the entire list stored in "ul". I am not able to remove the list item element using
firstListItem.removeChild(li)
Thanks for help
<!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>
let myList = document.getElementsByTagName('ul')[0];
let firstListItem = document.getElementById('first');
firstListItem.removeChild('ul');
Steven Parker
231,270 PointsNot quite — the name of the variable that has the reference to to child element is not "first" but "firstListItem".
1 Answer
Steven Parker
231,270 PointsTo use "removeChild", you need to call the method on the parent, and pass the child being removed as the argument.
In the previous tasks you have selected both the parent and child elements and stored them in variables, so now you can use those variables to call the method.
You won't need any string literals for the last task.
Morgan Welch
24,127 PointsMorgan Welch
24,127 PointsYou set firstListItem to document.getElementById('first') that just sets firstListItem to <li id="first">First Item</li>
firstListItem doesn't have any children so it does nothing.
What you want is