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 2

Robert Mews
Robert Mews
11,540 Points

Overlay Not Displaying

Can someone help me here? I cannot seem to get the overlay to display. I've doubled-checked my code. I must not be seeing where my error is.

Here is my CSS:

#overlay {
  background: black;
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
}

And my jQuery:

//Problem: User when clicking on image goes to dead end
//Solution: Create an overlay with the large image - lightbox

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

//Add overlay
$("body").append($overlay);
  //An image
  //A caption

//Capture the click event on a link to an image
$("#imageGallery a").click(function(event) {
  event.preventDefault();
  var href = $(this).attr("href");
  $overlay.show();
  //Show the overlay
  //Update overlay with the image linked in the link
  //Get child's alt atribute and set caption
});


//When overlay is clicked
  //Hide the overlay

Hi Robert,

I'm not seeing anything wrong with your code. In fact, I launched the workspace for this video and then pasted in your css and js and I was able to see the black screen as expected.

Did you save your files after adding in the new code?

There's possibly something wrong with the other code not shown here. You could give us a snapshot link if you're still having trouble.

https://teamtreehouse.com/forum/workspace-snapshots

Robert Mews
Robert Mews
11,540 Points

Hey Jason,

I saved my workspace. I did try again a few minutes later and it appeared. Maybe there was a server delay somewhere. It works now.

Best, Robert