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.

Aaron Coursolle
18,014 PointsWhy are no captions appearing?
Everything else in the lightbox appears to be working
//Problem: User when clicking on image goes to a dead end
//Solution: Create an overlay with a large image - lightbox
//The $-sign before overlay in "var $overlay" doesn't actually do anything
//It is placed in front of the variable for convention sake:
var $overlay = $('<div id="overlay"></div>');
var $image = $("<img>");
var $caption = $("<p></p>");
//An image to overlay
$overlay.append($image);
//A caption to overlay
$overlay.append();
//Add overlay
$("body").append($overlay);
//Capture the click event on a link to an image
$("#imageGallery 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 the overlay
$overlay.show();
//Get child's alt attribute and set caption
var captionText = $(this).children("img").attr("alt");
$caption.text(captionText);
});
//When overlay is clicked
$overlay.click(function () {
//Hide the overlay
$overlay.hide();
});
/** Start Coding Here **/
#overlay {
background:rgba(0,0,0,.7);
width:100%;
height:100%;
position:absolute;
top:0;
left:0;
display:none;
text-align:center;
}
#overlay img {
margin-top: 10%;
}
#overlay p {
color:white;
}
1 Answer
Brett Comardelle
8,541 PointsOn line 14, it seems that you aren't appending the $caption variable to your $overlay

Jeffrey Sullivan Jr
5,456 PointsIt looks like that isn't in the video, so I can see why it is easily missed if you are trying to follow along.

Yixi Guan
7,927 PointsIn teacher's code, there's another "$" is missing. I don't know if it was a mistake. Without the $ sign, my code wouldn't work.
$caption.text($captionText);
It's the one before captionText. Shouldn't it be required?
Aaron Coursolle
18,014 PointsAaron Coursolle
18,014 PointsThank you, Brett