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 trialRobert Rydlewski
3,828 PointsJava Script bug. : (
I tried fallowed the code but I am stuck in the bug for now 2 months and I am ready to quit if you can help me that would be assumed as I spend way to much time to find it. I followed the code and by the 1:36 when I add the let li = event.target;
let ul = li.parentNode;
ul.removedChild(li);
the code don't work. This is all JS code ```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 addIthemInput = document.querySelector ('.addIthemInput'); const addItemButton = document.querySelector ('.addItemButton'); const removeItemButton = document.querySelector ('.removedItemButton');
listDiv.addEventListener('mouseover',(event) => {
if (event.target.tagName == 'LI') {
let li = event.target;
let ul = li.parentNode;
ul.removedChild(li);
}
});
toggleList.addEventListener('click', () => { if (listDiv.style.display == 'none' ) {
listDiv.style.display = 'block';
toggleList.textContent = 'Hide list';
} else {
listDiv.style.display = 'none';
toggleList.textContent = 'Show list';
}
});
descriptionButton.addEventListener('click', () => { descriptionP.innerHTML = descriptionInput.value + ':'; descriptionInput.value = ''; });
addItemButton.addEventListener('click', () => { let ul = document.getElementsByTagName('ul')[0]; let li = document.createElement('li'); li.textContent = addIthemInput.value; ul.appendChild(li); addIthemInput.value = ''; });
removeItemButton.addEventListener('click', () => { let ul = document.getElementsByTagName('ul')[0]; let li = document.querySelector('li:last-child'); ul.removeChild(li);
});
1 Answer
Antonio Pala
Front End Web Development Techdegree Student 16,928 PointsHi Robert, you have a few typos in your code:
1) ul.removedChild(li); should be ul.removeChild(li); 2) const addIthemInput = document.querySelector ('.addIthemInput'); should be const addItemInput = document.querySelector('.addItemInput');
Let us know if you still have issues!
Steven Parker
231,236 PointsSteven Parker
231,236 PointsTo allow the issue to be easily replicated, make a snapshot of your workspace and post the link to it here.