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) Getting a Handle on the DOM Select a Page Element By Its ID

It throws this error: Uncaught TypeError: Cannot read property 'addEventListener' of null at app.js:4

I looked at the HTML very carefully and there was not any errors. But it still says: Uncaught TypeError: Cannot read property 'addEventListener' of null at app.js:4

Hi Lucas,

Youโ€™d really need to post your code in order for someone to offer the best advice, as itโ€™s difficult to debug without being able to test code.

That said, based on the error and a review of the video, Iโ€™m guessing that your myButton variable (Iโ€™m assuming youโ€™re calling addEventListener on myButton) doesnโ€™t actually hold a value. This would happen if the element youโ€™re trying to select canโ€™t be found in the DOM.

Try logging out whatever variable youโ€™re calling addEventListener on to see if it holds a value.

1 Answer

Thank you. I figured out what the problem was; I put the script tags after the HTML.