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!

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.