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

I am doing something wrong with my lightbox. I need help, Please !

My lightbox seemed to be working fine until I get to Perform:Part 3. The images in the gallery go to their default settings. Which of course is not what I want.

This is my code: ```var $overlay = ('<div id="overlay"></div>'); var $image = $("<img>");

$overlay.append($image);

$("#statements").append($overlay);

//Overlay End

$("#imageGallery a").click(function(event){ event.preventDefault(); var imageLocation = $(this).attr("href"); $image.attr("src", imageLocation);

$overlay.show();



});

```

This is my CSS:

#overlay{
    background: rgba(255,255,255,0.7);
    width: 90%;
    height:220px;
    position:absolute;
    display:none;   
}

May someone look at my code and tell me what I am doing wrong please. I have watched the video several times but I am obviously still missing something. Thank you in advance.

What do you have your var statements set to at the top of the app.js (around lines #4-5)? Mine are set as follows: var $overlay = $('<div id="overlay"></div>'); var $image = $("<img>");

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


$overlay.append($image);

$("#statements").append($overlay);





$("#imageGallery a").click(function(event){
    event.preventDefault();
    var imageLocation = $(this).attr("href");
    $image.attr("src", imageLocation);


    $overlay.show();



    });

    ```

Sorry I didn't display my code properly.

1 Answer

I noticed you are appending the overlay to #statements. I am appending the overlay to body.

Yes the div that I am appending it to that it it'd id. I didn't append it to body because the gallery does not take up the entire page.