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

xingyi zhao
xingyi zhao
Courses Plus Student 1,020 Points

Append doesn't work

I copy the code

//problem: user when clicking on image goes to a dead end
//create an overlay with the large image-Lightbox
var $overlay = $('<div id="overlay"></div>');
//add overlay
//an image
//a caption

//1.capture the click event on a link to an image
$("#imageGallery a").click(function(event){
 var href= $(this).attr("href");
  //1.1show the overlay
  //1.2 update overlay with the image linked in the link
  //1.3 Get child's alt attribute and set caption

//2. Add overlay
  //2.1 an image
  //2.2 a caption
//3. When overlay is clicked 
  //3.1 Hide the overlay

but it doesn't work

Nina Kozlova
Nina Kozlova
11,602 Points

What do you see in the console?

xingyi zhao
xingyi zhao
Courses Plus Student 1,020 Points

Only thing I saw in console is :"Failed to load resource: the server responded with a status of 404 (Not Found)"

3 Answers

Julien riera
Julien riera
14,665 Points


Is your script tag path correctly written in your html ?

Tushar Singh
Tushar Singh
Courses Plus Student 8,692 Points

did you check your script path?

or did you use css to change your overlay , because right now its empty, as your div is empty you won't see a thing really(nothing wrong with the js code), if you are looking for any image in your body while appending, you have to append those images to your overlay, then only you can see them.


<div id="overlay"></div>   <!-- nothing to show -->
Tushar Singh
Tushar Singh
Courses Plus Student 8,692 Points

Try adding this, you should see Hello World in your body

<div id="overlay">Hello world</div>  <!-- in your js code, add a text for testing purposes -->

If it doesn't work, check your script tag and if all of this dosen't work, lemme know.

Rodrigo Castro
Rodrigo Castro
15,652 Points

Hi I was having the same problem, it turned up I made a mistake in my CSS.