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 trialJohn 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 34,660 PointsBrandon White
Full Stack JavaScript Techdegree Graduate 34,660 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.