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 trialjlampstack
23,932 PointsAppending Image to Overlay Div?
The way the code is written, when we append $image to $overlay I imagine the <img> tag going after the <div> tags opposed to in between them?
This is how I visualize it after being appended...
<div id="overlay"></div>
<img> // img is after
How is it that the <img> goes between? This is how I believe the result should look....
<div id="overlay">
<img> // img is between
</div>
Instructors code
const $overlay = $('<div id="overlay"></div>');
const $image = $('<img>');
$overlay.append($image);
2 Answers
Reuben Varzea
23,182 PointsjQuery's append() is used to add one element INTO another. One thing you would note, though, if that particular DIV contained other elements, an H1 for example, the append would add that IMG element after the H1, but still inside of the DIV.
You can read a little more about how append() works in the jQuery documentation: http://api.jquery.com/append/
jlampstack
23,932 PointsOK great! That makes perfect sense to me now.