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
John Piaz
1,713 PointsIt 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
1 Answer
John Piaz
1,713 PointsThank you. I figured out what the problem was; I put the script tags after the HTML.
Brandon White
Full Stack JavaScript Techdegree Graduate 35,773 PointsBrandon White
Full Stack JavaScript Techdegree Graduate 35,773 PointsHi 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.