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

Why can't we just add an 'alt' attribute with 'captionText' to the $image? Why do we need to append a paragraph instead?

$image.attr("alt", captionText);

Lucas,

Could you provide further context? A link to the video/challenge you're referring to, perhaps?

Erik

1 Answer

Steven Parker
Steven Parker
243,656 Points

:point_right: These two things have very different purposes.

The text in an alt attribute would not be visible by default. It might become visible if the cursor is placed on the image, depending on the browser. But the primary use for alt is to be displayed when the image cannot be rendered for some reason, or to assist screen readers used by sight-impaired users.

On the other hand, a paragraph would always be visible.