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

CSS jQuery Basics (2014) Creating a Simple Lightbox Perform: Part 4

Lightbox won't click away.

At the end of the course I got everything to look and act right. But when I click on an image, the lightbox pops up and no amount of clicking will make it go away. I don't understand what I've done to keep it from going away. Any Help?

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

$overlay.append($image);

$overlay.append($caption);

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

$("#imageGallery a").click(function(event) { event.preventDefault(); var imageLocation = $(this).attr("href");

$image.attr("src", imageLocation);

$overlay.show();

var captionText = $(this).children("img").attr("alt"); $caption.text(captionText);

});

$overlay.click(function() { $overlay.hide

});

Post your code...it will be easier to see where you've gone wrong.

1 Answer

Hello Erik!

I think the problem is due to the missing () after .hide in your last function.

Instead of

$overlay.click(function() { $overlay.hide;})

you should write

$overlay.click(function() { $overlay.hide();})

Thank You!