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 trialRossella Rosin
15,734 Pointswhy use text() and not append() for the caption too?
Is there any particular reason, apart from teaching us a different method, why we used
$caption.text(captionTxt);
instead of
$caption.append(captionTxt);
which seems to work fine as well, at least on chrome. After all, a text node is always a node.
1 Answer
Steven Parker
231,269 PointsIt might appear to work the same, but only because the element had no text to begin with.
- .text() completely resets the element text. If there was any there before, it is replaced with the new.
- .append() adds an additional text node to the element. Any text already there will still be seen with the new.
Try using append and see what happens when you use the overlay a second time (or third, etc).
Rossella Rosin
15,734 PointsRossella Rosin
15,734 Pointsthank you!