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 trial

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,028 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,028 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