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

I want to know why does the overlay show page without a click .

I want the image to show on the overlay and what is happening is just the overlay is showing without a click / and its showing as soon as the page loads / and it doesn't allow me to choose a pic , because the overlay automatically shows as the page loads . why is this ?

     var $image = $("<img>");



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

      $overlay.append($image);

     $("body").append($overlay);


      $(".pic-nav li img ").click( function(e) {

           e.preventDefault();

           var loc = $(this).attr("src");

            $image.attr("src", loc);


          $overlay.show();

      });

          ```js

 the code.

2 Answers

Steven Parker
Steven Parker
243,656 Points

Unless it's in the CSS (not included), you didn't do anything to conceal it initially. One way to do that would be to call the .hide() method on it as you create it like this:

     var $overlay = $('<div id="overlay" style="display:none"></div>');

I did that in the css now and that was the case thanks but now the image does not appear along with overlay