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.

JavaScript JavaScript and the DOM (Retiring) Making Changes to the DOM Styling Elements

My 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
Kieran Barker
15,004 Points

Is it definitely an ID, not a class?

Oh, thank you thank you thank you!!! There was the mistake :S Now it works perfectly!

Kieran Barker
Kieran Barker
15,004 Points

No 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