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

What mistake am I doing in this code challenge.?

What mistake am I doing in this code challenge.?

index.html
<!DOCTYPE html>
<html>
    <head>
        <title>DOM Manipulation</title>
    </head>
    <link rel="stylesheet" href="style.css" />
    <body>
        <ul id= "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 = input.value('ul');
let firstListItem;

3 Answers

Hi Mike

Assuming you are on the first challenge Try this

let myList = document.querySelector("ul");

This selects the element and stores it in the variable, not the value.

Hope this helps. Happy coding

Paul

What mistake am I doing in the last step of this challenge :

let myList = document.querySelector("ul");
let firstListItem= document.querySelector("#first");
firstListItem.removeChild('#first');
let myList = document.querySelector("ul");
let firstListItem= document.querySelector("#first");
firstListItem.removeChild('#first');

The last task of the challenge is:

Remove the list item element stored in firstListItem from the DOM

You're currently trying to remove the firstListItem from itself, which can't work. You have to remove the element stored in the firstListItem variable from the list element stored in the myList variable.

Hope it helped!

Brice Roberts
Brice Roberts
22,415 Points

I am assuming that this is for step #1??

If so, input.value is not correct.

input.value is to reflect a value that you want to set once you have instantiated it's location..

For this step, you have to reference the list location in the DOM.

If that doesn't make sense.. pause the previous video around the 1:30 mark, and compare what you have tried to the example.

HINT: you need to get the field by it's tag

Still cannot figure out, what is the mistake with above step 3 in the challenge. Can someone post solution please?

Try:

myList.removeChild('#first');