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 trialDoug Hawkinson
Full Stack JavaScript Techdegree Student 25,073 PointsjQuery Challenge - I'm not even sure what they are asking for
This is the challenge:
Using jQuery only, add to all links with the class "external", the target attribute with the value of "_blank".
I have tried a couple of things as pure guesses. It boils down to the fact that I am not even sure what the challenge is. I think my biggest problem is I don't know what is meant by "target attribute".
3 Answers
Donald Brunais
8,895 PointsWhat is asking is to add a new attribute with the name of target and the value of '_blank' to every tag that has the class of external. So there is two anchor tags with the class of external. You just add target='_blank' within the tag.
<li><a href="http://google.com" class="external">Google</a></li>
<li><a href="http://yahoo.com" class="external">Yahoo</a></li>
to
<li><a href="http://google.com" class="external" target='_blank'>Google</a></li>
<li><a href="http://yahoo.com" class="external" target='_blank'>Yahoo</a></li>
Doing this in JQuery looks like
$('.external').attr('target', '_black');
Anthony Mejia
8,840 PointsHey Doug,
Seems like someone had a similar problem a couple months back. Here's the link to their thread.
Hope this helps!
Doug Hawkinson
Full Stack JavaScript Techdegree Student 25,073 PointsDonald:
That was simple. There was just something clumsy in the way the challenge was specified that caused me not to "connect". Thanks for the help.
Jesus Bayona
4,937 PointsJesus Bayona
4,937 PointsI seen this in another post concerning this question and it works. What's the difference?
$("a.external").attr('target' ,'_blank');
Donald Brunais
8,895 PointsDonald Brunais
8,895 Points$("a.external").attr('target' ,'_blank'); Is selecting all anchor tag with the class of external. In this example either would work it doesn't change the end result. So if had a paragraph tag in the html with the class of external <p class='external'> ... </p>
$("a.external").attr('target' ,'_blank'); wouldn't select the new p tag. $(".external").attr('target' ,'_blank'); would select the new p tag