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 jQuery Basics (2014) Creating a Simple Lightbox Perform: Part 3

Robert O'Brien
Robert O'Brien
581 Points

$overlay.append(); is not a function

When I go to check it out in the browser, clicking on the image just takes me to the dead end. The console.log says that $image.append(): is not a function. I've looked at it a bunch of times and I'm pretty certain that's what is shown in the video and it works fine. Not really sure where to go from here.

Tony Nguyen
Tony Nguyen
24,934 Points

What's your full javascript/jquery code?

Robert O'Brien
Robert O'Brien
581 Points

this is the full code:

//problem: clicking on image ends in dead end, which is a poor user experience //solution: create overlay with the large image ie lightbox

var $overlay = ('<div id="overlay"></div>'); var $image = $("<img>");

//an image to overlay $overlay.append($image);

// add overlay $("body").append($overlay);

//add image //add a caption

// capture click event on a link to an image $("#imageGallery a").click(function(event){ event.preventDefault(); var imageLocation = $(this).attr("href"); //1.2 update overlay with the image linked in the link $image.attr("src", imageLocation);

// show the overlay $overlay.fadeIn();

//1.3 get child's alt attr and set caption

});

//3. when overlay is clicked $overlay.click(function(){ $(overlay).fadeOut

}); //3.1 hide the overlay

Robert O'Brien
Robert O'Brien
581 Points

ok, so now it works. i haven't changed anything, but no errors come up in the console.log. maybe i just had to clear the cache?