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

I dont know why the overlay is not being hidden after I click

//problem: user gets to dead end when clidking image //solution: create an overlay with a large image - Lightbox

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

$overlay.append($image);

//add overlay

$("body").append($overlay); //an image //a caption

//caption a click event on a link to an image

$("#imageGallery a").click(function(event){ event.preventDefault(); var imageLocation = $(this).attr("href"); //update overlay with image linked in link

$image.attr("src", imageLocation)

//show the overlay

$image.show();

//get the childs alt attr

});

//when overlay is clicked

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

$overlay.hide();

});

1 Answer

Hi! You haven't shown the overlay. I believe this line

//show the overlay

$image.show();

should be in fact.

//show the overlay

$overlay.show();

You have appended the image to the overlay, so this will show the overlay with the image on it.

also, I think you are missing semicolons after the variable declarations. Also the quotations are off. You should use single quotes for the 'overlay' id.

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

should be

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