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
Lily Peterson
10,685 PointsAdding New Attribute Values
I don't know how to do this right. I'm supposed to use the '.attr()' method, but I don't know how to use it properly in this code. I need to set a 'target' attribute with the value of '_blank' to all links with the class 'external'. How do I do that? $("external").attr("target"); $("target").attr("_blank");
1 Answer
Erik Nuber
20,629 Pointsto set something using the attr() method you have to do .attr("what you are going to set", "what you are putting into that");
.attr( attributeName, value )
$(".external").attr("target", "_blank");
So this gets the class external and sets the attribute Target to open the linked document in a new window or tab
Lily Peterson
10,685 PointsLily Peterson
10,685 PointsThanks.