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

Lucian Dumitru
PLUS
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
231,275 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.