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 trialanthonybrackner
17,776 PointsCode Not Working
const listDiv = document.querySelector('.list'); const listUl = listDiv.querySelector('ul');
listUl.addEventListener('click', (event) => { if (event.target.tagName == 'BUTTON') { let li = event.target.parentNode; let ul = li.parentNode; ul.removeChild(li); } });
The above code is not working and I have no idea why. It appears to be what Guil is coding himself. What a frustrating module.
4 Answers
Andreas Nyström
8,887 PointsHi Anthony.
From what I can see your code looks correct, but that is out of context. When asking questions try using the Markdown for what you're trying to show. See more here: https://teamtreehouse.com/community/howto-guide-markdown-within-posts.
Also I think we need to see the rest of the code to help you here.
So maybe you can snapshot your workspace and paste it here? To do this:
- You go to your workspace and click the thirt button from the right on the top-right corner. (It looks like a camera).
- Share the link here (like this one! https://w.trhou.se/3c329u10z1)
Or you could paste all the code in here, but it's simpler for us if you just snapshot it if its a lot of code :).
anthonybrackner
17,776 PointsThanks Andreas, will that do?
Andreas Nyström
8,887 PointsHi again Anthony.
Your code that you displayed here was correct. However, on line 25:
toggleList.addEventListener('click', function() {
if (listDiv.style.display == 'none') {
toggleList.textContent = 'Hide list';
listDiv.style.display = 'block';
} else {
toggleList.textContent = 'Show list';
listDiv.style.display = 'none';
}
You forgot to end your eventlistener. So the code on line 25 should be:
toggleList.addEventListener('click', function() {
if (listDiv.style.display == 'none') {
toggleList.textContent = 'Hide list';
listDiv.style.display = 'block';
} else {
toggleList.textContent = 'Show list';
listDiv.style.display = 'none';
}
});
I think this is all you need to do. If you're having trouble with the code sometime, try bringing up the console in your browser. See how here: https://kb.mailster.co/how-can-i-open-the-browsers-console/
There is often an explanation on why it's not working and then you can see where and what the bug is.
Hope this helps, keep at it and happy coding!
anthonybrackner
17,776 PointsThanks so much Andreas! I was looking at every part of the code except for that section.