Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Rick Love
5,312 PointsAdding Item isn't working
My li isn't getting added to the page???
const toggleList = document.getElementById('toggleList'); const listDiv = document.querySelector('.list'); const descriptionInput = document.querySelector('input.description'); const descriptionP = document.querySelector('p.description'); const descriptionButton = document.querySelector('button.description'); const addItemInput = document.querySelector('input.addItemInput'); const addItemButton = document.querySelector('input.addItemButton');
toggleList.addEventListener('click', () => { if(listDiv.style.display == 'none'){ toggleList.textContent = "Hide List" listDiv.style.display = 'block'; } else { toggleList.textContent = "Show List" listDiv.style.display = 'none'; } });
descriptionButton.addEventListener('click', ()=>{ descriptionP.innerHTML=descriptionInput.value + ':'; });
addItemButton.addEventListener('click', () => { let ul = document.getElementsByTagName('ul')[0]; let li = document.createElement('li'); li.textContent = addItemInput.value; ul.appendChild(li);
});
1 Answer

Steven Parker
216,151 PointsThere's no obvious issue in this JavaScript code.
But this code clearly works with an HTML component, and the issue may be there.
When asking about issues with multi-source projects, it might be best to make a snapshot of your workspace and post the link to it here.
And when posting code directly, always use the instructions for code formatting in the Markdown Cheatsheet pop-up below the "Add an Answer" area.
Or watch this video on code formatting.
SAMUEL LAWRENCE
Courses Plus Student 8,447 PointsSAMUEL LAWRENCE
Courses Plus Student 8,447 PointsHi Steven Parker I'm having the same issue, Can't figure it out myself. Everything seems ok and as you said there is nothing wrong with the code above, my code is the same. I took your advice and checked the HTML, I couldn't see anything wrong either. Can you help out?
JavaScript
In my code here I added the conditional statement I asked you about in an earlier question.
In my HTML file you'll notice the name of the
.js
file is not namedapp.js
that's because I create separate files for each lesson, just in case I'm stuck I can go back to a specific lesson and look at the code again. but apart from that nothing is different.Steven Parker
216,151 PointsSteven Parker
216,151 Points