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

JavaScript jQuery Basics (2014) Creating a Simple Lightbox Perform: Part 3

Rob Bartlett
Rob Bartlett
6,741 Points

Hide Overlay Breaks Code

Everything is working just fine with the overlay popping up and breaking out the image with this:

// Problem: When clicking on image, user goes to dead end
// Solution: Create an overlay with the large image - Lightbox

var $overlay = $('<div id="overlay"></div>');
var $image = $("<img>");

//    Add image to overlay
$overlay.append($image);

//Add overlay
$("body").append($overlay)

//    2 A caption


//Capture the click event on a link to image
$("#imageGallery a").click(function (event){
  event.preventDefault();
  var imageLocation = $(this).attr("href");

  //    Update overlay with the image linked in the link - image pops out
 $image.attr("src", imageLocation);

  //    Show the overlay - background darkens
$overlay.show();

  //    Get child's alt atribute and set

});

But then, when I take the next step -- verbatim from the video... I think -- the overlay no longer works, and it opens the linked file.

// When overlay is clicked
$overlay.click(function(){
//    Hide the overlay
  $overlay.hide();
}
//

What. Gives.

2 Answers

Colin Marshall
Colin Marshall
32,861 Points

Looks like you're missing a right parenthesis and a semicolon at the end of your click method. See if this fixes it:

// When overlay is clicked
$overlay.click(function(){
//    Hide the overlay
  $overlay.hide();
});
//
Rob Bartlett
Rob Bartlett
6,741 Points

I knew it was going to be something stupid like that. Thank you, good eye.