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 trialPatricia Martin
5,477 PointsMy code doesn't work properly...
I'm following the video steps but my code doesn't work properly. I used the console to see where the problem is and this is the message that appears: "Uncaught TypeError: Cannot read property 'addEventListener' of null at app.js:7"
const toggleList = document.getElementById("toggleList"); const listDiv = document.querySelector(".list"); const input = document.querySelector("input.description"); const p = document.querySelector("p.description"); const buttton = document.querySelector("button.description");
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"; } });
buttton.addEventListener("click", () => { p.innerHTML = input.value + ":"; });
Someone who can help me? I have reviewed the code a thousand times and I can not find the error :(
Thank you in advance!
2 Answers
Kieran Barker
15,028 PointsIs it definitely an ID, not a class?
Patricia Martin
5,477 PointsOh, thank you thank you thank you!!! There was the mistake :S Now it works perfectly!
Kieran Barker
15,028 PointsNo problem. Also, are you sure all those constants are supposed to have those description
classes in their selectors? Thatβs not what it looked like when I skimmed through the video. And you might want to change buttton
to button
:D