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 Interactive Web Pages with JavaScript Traversing and Manipulating the DOM with JavaScript Perform: Traversing Elements with querySelector

rajbee
rajbee
6,657 Points

Uncaught TypeError: Cannot read property 'querySelector' of undefined

I see the below error in my code. Please help me to find the cause and fix it.

Uncaught TypeError: Cannot read property 'querySelector' of undefinedbindTaskEvents @ app.js:60(anonymous function) @ app.js:82

workspace - https://w.trhou.se/8mu1vp41wb

EDIT - I found that it was due to typos. I forgot to put the termination conditions i < blah.... in the for loops at the bottom and should have taskIncomplete instead of tasksIncomplete in the last for loop.

Can someone explain why the error occurs ? Why is the property undefined ?

Hello,

The reason this error occurred is because of exactly what you said "should have taskIncomplete instead of tasksIncomplete in the last for loop."

How do you know what caused the error?... Well look at the error message carefully and you will see that it cannot read the property of undefinedbindTaskEvents. You're using bindTaskEvents where your typo was and the 'querySelector' is referring to the last param of bindTaskEvents.

This explains why it couldn't read the property 'querySelector' (tasksIncomplete) for bindTaskEvents.