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

HTML jQuery Basics (2014) Creating a Simple Lightbox Perform: Part 1

Robert Ungar
Robert Ungar
15,723 Points

Javascript Lightbox: Cannot read property 'parentNode' of undefined

I'm having trouble with the Lightbox video for Javascript. When running the console, I keep getting this error:

Uncaught TypeError: Cannot read property 'parentNode' of undefined popup.js:61(anonymous function) popup.js:61(anonymous function)

This is my code:

//1. Capture the click event on a link to an image
$("#imageGallery a").click(function(event) {
  var href = $(this).attr("href");
  //1.1 Show the overlay
  //1.2 Update overlay with the image linked in the link
  //1.3 Get child's alt attribute and set caption


Hi Robert,

I went ahead and fixed your code formatting for you.

This thread shows you how to post code: https://teamtreehouse.com/forum/posting-code-to-the-forum

Sean T. Unwin
Sean T. Unwin
28,690 Points

Hi Robert Ungar,

Is the click function you posted on line 61 of popup.js? Trying to determine if the posted code is, in fact, where the error is coming from.

A follow-up question - Is #imageGallery spelled the same way in the HTML? Just curious if there is a typo.

Robert Ungar
Robert Ungar
15,723 Points

Hey Sean T. Unwin,

Thanks for the quick reply. It seems to have just started working so I'm not sure what the problem was. I'm not able to duplicate the error now but I believe it may have been popup.js. I checked the HTML file and had #imageGallery properly spelled.

In any case, thanks for jumping in!


Sean T. Unwin
Sean T. Unwin
28,690 Points

No worries. :)

Glad you have it worked out.