Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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
216,121 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!