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

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
231,269 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
231,269 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.