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 jQuery Basics (2014) Creating a Simple Lightbox Adding New Attribute Values with attr()

Chris Kelp
Chris Kelp
5,253 Points

I don't understand the wording of this question. Is this close at all? $(".external").target("_blank");

trying to target .external, i think

John Coolidge
John Coolidge
12,614 Points

Are you stuck on a code challenge question? If so, could you post the question or let us know the name?

Also, if you are stuck, you can click on the "get help" button on the code challenge and it will link the code challenge you're on to the question so that we can review it along with your question.

John

2 Answers

Greg Kaleka
Greg Kaleka
39,021 Points

Hi Chris!

You are close. I agree the wording is pretty hard to grasp.

What the challenge is asking you to do is to select all the links with the class external, and give them all the attribute target, with a value of _blank. You need to add the a element so you're selecting links, and you need to use the attr function in jQuery, which takes two arguments: the attribute, and the value you want to set it to. In our case, that's "target" and "_blank":

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

Happy coding!

-Greg

John Coolidge
John Coolidge
12,614 Points

Forgive my earlier comment, you did link it to the code challenge. My apologies.

First, I'll post the answer to the code challenge, then I'll explain it.

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

You need to select all the links with the class external.

$('a.external');

Next, you need to alter their attribute, specifically the attribute called target. You do this by adding .attr() to the end of the jquery object you created that targets all links with the class external. Inside the .attr() method you need two arguments. The first, as shown below, is the attribute you want to edit, in this case, target.

$('a.external').attr('target', );

Finally, you need to use the space for the second argument to change the attribute. In this case, you are changing the value of the attribute target to _blank.

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

Additionally, you don't need to use the $(a.external') in the exercise. You can simply use $('.external), but the former is more specific and in larger projects would be best practice.

I hope that makes sense. If you have any other questions feel free to ask!

John