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

Just curious, why .external instead of #external?

Hey there! I figured out the solution, but after looking at the examples on the .attr() .api page all list answers that would make my solution look like

("#external").attr("target", "_blank");

instead of the proper solution with (".external").attr etc...

Just curious, why is this? Is it because the class=external is not the first in the list of values? or that there are several items with the class=external value? Thanks!

(if for some reason this doesn't show up in the right forum, it should be for: JavaScript > jQuery Basics > Creating a Simple Lightbox > Adding New Attribute Values with attr())

1 Answer

Steven Parker
Steven Parker
229,670 Points

Because the challenge asks you to: add to all links with the class "external", the correct solution to the challenge is:

$("a.external").attr("target", "_blank");

If you substitute "#external" in the selector, that would target a link that has the id (not class) "external". There are no elements in the provided HTML that have that id, (and there could only be one at most, since id's must be unique).

Oh! That makes everything make so, so much more sense. Thank you!