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
Samuel Biggs
15,432 PointsAdding New Attribute Values with attr(), Coding Challenge in JQuery Basics - incorrectly worded challenge
Hey guys, just wanted to post this up, unsure if it needs to go to the Treehouse staff or anything, but for future reference:
In the above Coding Challenge, you are told to add the .attr to everything with the class 'external'. This is not correct. You are in fact required to add the .attr to all items with an 'a' tag, or in other words the [i]anchors[/i] of the class, not the class itself.
Got really frustrated when my code - which was perfect as requested by the task - kept getting thrown out and did this just in case. Cue amazement when it passed. So, just something to keep in mind!
Also, does anyone know how to link relevant videos/challenges to the question? Searched on the forum and nothing shows up...
This is the link to the challenge, just wondered if there's a way to do it that shows the actual name from the course header, as that's what most people would see it as: https://teamtreehouse.com/library/jquery-basics/creating-a-simple-lightbox/adding-new-attribute-values-with-attr
Samuel Biggs
15,432 PointsHi Jason - thanks for the tip about the video, I didn't realise it did that as well - I thought it just sent you to the Forum, so I'll keep that in mind :)
As to the code I used, originally it was: $("external").attr("target", "_blank")
This kept coming up wrong, so I changed it to:
$("a").attr("target", "_blank")
Which went through fine. Also, it does not say for 'a' tags with the class 'external', but just the class 'external' by itself - if it had said it was after the 'a' tags to begin with, I wouldn't have had a problem with it :)
Thanks for the help, btw!
Jason Anello
Courses Plus Student 94,610 PointsAs Iain already mentioned, you would need a dot in front since it's a class.
.external or more specific a.external
$("a") really shouldn't be passing the challenge because it's selecting all the links on the page. Not just the ones with a class of "external"
I'll notify the staff of that problem.
Samuel Biggs
15,432 PointsThanks for the help, guys - btw, just to check, I ran through it again using ".external" instead of "a", and that was fine, so it just looks like a bit of a blip on the verification side of things. I completely forgot about using the "." for a class! #wheremybrainat
Thanks again :)
2 Answers
Jason Anello
Courses Plus Student 94,610 PointsHi Samuel,
I don't think there's anything wrong with the challenge instructions.
It states -
add to all links with the class "external"
An example of one of those links in the html is -
<a href="http://google.com" class="external">Google</a>
You are correct that the links are a tags but it's specifically asking for a tags that have a class of "external" like the google link above.
On a larger page you would normally have other internal links to your other pages and these wouldn't have a class of "external" with them. You're not meant to target all links, only the ones with a class of "external".
You didn't post what you had tried that you thought was correct but feel free to post that and we can try to explain why it might have been wrong.
Iain Simmons
Treehouse Moderator 32,305 PointsNote that your syntax for a class selector in jQuery is incorrect, as you're missing the leading period/dot:
$("external").attr("target", "_blank")
Should be:
$(".external").attr("target", "_blank")
And technically if you wanted to restrict to only links (a tags), you'd put that before the dot.
Jason Anello
Courses Plus Student 94,610 PointsJason Anello
Courses Plus Student 94,610 PointsVideos, quizzes, and code challenges have a "Get Help" button. If you ask your question through that interface then the content will be automatically linked to your question.