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 trialMUZ140989 Eukael Mbuyisa
6,395 PointsYou know what? The alt attribute should be more descriptive of what the image is. The title attribute is better use for
it keeps saying bummer add variable
2 Answers
Greg Kaleka
39,021 PointsHi Eukael,
I'm not sure what you've done in this challenge, so it's hard to know why you're getting that error. This is a pretty simple challenge (although I have to say the question is long and hard to understand). All you have to do is change the $captionText variable from using the alt
attribute to using the title
attribute. See below.
//Problem: User when clicking on image goes to a dead end
//Solution: Create an overlay with the large image - Lightbox
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($caption);
//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 title attribute and set caption
var captionText = $(this).children("img").attr("title"); // *** Change made here ***
$caption.text(captionText);
});
//When overlay is clicked
$overlay.click(function(){
//Hide the overlay
$overlay.hide();
});
MUZ140989 Eukael Mbuyisa
6,395 Pointsthanx alot l got it