Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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>');