Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript jQuery Basics (2014) Creating a Simple Lightbox Perform: Part 3

Why is $overlay.append($image); above $("body").append($overlay);?

The structure is: image in overlay in body.

I don't understand why is $overlay.append($image); above $("body").append($overlay);

1 Answer

Steven Parker
Steven Parker
216,032 Points

I don't think the order is important.

Making the overlay complete before adding it to the document body means the browser only has to update once, but in practice doing it the other way would likely happen to fast to see any difference.

Thank you Steven. So unlike CSS cascading from top to bottom in order, in Javascript and jQuery, order doesn't matter?

Steven Parker
Steven Parker
216,032 Points

As a general rule, order will be important. But for these specific two statements, the end result will be the same for either order of execution.

But as I pointed out, the intermediate state between them will not affect the browser display in the order shown in the video, but it would if they are reversed.