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.

Craig Watson
Courses Plus Student 27,126 PointsHi I Cant Spot the error?
Hi everyone,
Looked over this code a number of times but I cant find the issue really need a fresh set of eyes !
The issue im having is that the the overlay is showing instantly thus preventing being able to click on the links....
var $overlay = $('<div id="overlay"></div>');
var $image = $("<img>");
$overlay.append($image);
// Add overlay
$("body").append($overlay);
// An image
// A caption
// Capture the click event on a link to an image
$("#image-gallery a").click(function(event){
event.preventDefault();
var imageLocation = $(this).attr("href");
// Update overlay with the image linked in the link
$image.attr("src", imageLocation);
// Show overlay
$overlay.show();
// Get Childs alt att and set caption
});
Thanks! Craig

mtch
8,521 PointsTry removing the hyphen in "#image-gallery a".

Craig Watson
Pro Student 27,126 PointsHi everyone!
I have used the: $overlay.hide(); at the end of my code outside the function and it seems to have cured the problem the only strange thing is that I've re-watched the video and at no point does Andrew Chalkley add this code :S
My code seems to me to match but only when adding the above does it perform in the same way....
Maybe Andrew being the extremely kind could try to explain this one because its gone well over my head ....
Thanks everyone im glad I have a solution in the mean time to carry on with course!
Thanks Again!
2 Answers

Jonathan Sebastiao
14,271 PointsI believe you have to hide the $overlay now. You have it showing without it being hidden after.
```$overlay.click(function(){$overlay.hide();)}; ```

oseijenkins
12,912 PointsI agree. Not having this will give users no way to close the overlay, outside of refreshing the page

Craig Watson
Pro Student 27,126 PointsHi everyone!
Just thought id update you all on the error of my ways.....
Clearly my listening and watching skills were at a null on the day I first watched the video in question, as right at the end Andrew tells us to ad a display: none property and value to the #overlay in the css file.....
Thank you all for your help!
Craig

Jonathan Sebastiao
14,271 PointsWell that makes a lot of sense too. Good to know.
Elliot Alderton
11,955 PointsElliot Alderton
11,955 PointsI think its because your $("body").append($overlay); is showing the overlay (it isn't hidden when you append it). You could try $("body").append($overlay); $overlay.hide();