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
Paige Jordan
7,054 PointsWhy isn't my lightbox image gallery working?
I have double checked my code and can't seem to get the image to open as a lightbox image gallery; when the image is clicked it is still opening as it's own file like I haven't changed anything at all. I have saved my files, refreshed the page, closed the window and reopened it through work spaces, logged out and logged back in and nothing seems to work. What have I done wrong?
var $overlay = $('<div id="overlay"></div>');
var $image = $("<img>");
var $caption = $("<p></p>");
$overlay.append($image);
$overlay.append($caption);
$("body").append($overlay);
$("#imageGallery a").click(function(event){
event.preventDefault();
var imageLocation = $(this).attr("href");
$image.attr("src", imageLocation);
$overlay.show();
var captionText = $(this).children("img").attr("alt");
$caption.text(captionText);
});
$overlay.click(function() {
$overlay.hide();
});
1 Answer
Chris Shaw
26,676 PointsHi Paige,
I just tried all the above out in my own workspace and it worked as expected minus the styles, see the below link which is my workspace.
http://web-y9rt1ikqxb.treehouse-app.com/Paige%20Jordan/
The only other reason this would happen is if your JavaScript didn't load due to an incorrect path which you can see by looking in your browsers developer tools console, if you don't know how to get there the global shortcut for all browsers is F12.
Paige Jordan
7,054 PointsPaige Jordan
7,054 PointsIt might also help to see the html: