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

Lucian Dumitru
Lucian Dumitru
Courses Plus Student 13,024 Points

Why did Andrew used the variable var $image = $("<img>") when he appended $image to $overlay ?

Why did Andrew used the variable var $image = $("<img>") when he appended $image to $overlay and not var $image =$("<img") without the closing ">" if the .append() method adds the html code to the end of each element in the set of matched elements ?

1 Answer

Steven Parker
Steven Parker
222,348 Points

The tag must be complete to create a new element without error.

Using "<img" without the closing ">" would be an incomplete tag, and would not be a valid argument for creating a new element.