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

Werner Chao
PLUS
Werner Chao
Courses Plus Student 1,951 Points

Regarding moving '2. Add overlay' to top

Hi, I didn't understand why the instructor decided to move the '2. Add overlay' to top, above the original step 1. This line here:

$("body").append('<div id = "overlay"></div>');

I understand that it is useful to use the overlay as a variable, but I don't understand why and how it affects the outcome by moving 'Step 2. Add overlay' to top.

Thanks!

1 Answer

Sergey Podgornyy
Sergey Podgornyy
20,660 Points

Because he want to create this element first and show it only after click on image.

Werner Chao
Werner Chao
Courses Plus Student 1,951 Points

Ah I see! Thank you! What would happen if he creates the element only after click on image? Would that work?

Sergey Podgornyy
Sergey Podgornyy
20,660 Points

You are welcome!

Yes, it will work, but then you need to create new element every time you press the button. And then remove this element from DOM tree.

If you once created this element, everything you need - just show and hide it.