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()

Code challenge doesn't seem to actually be evaluating code

The question requires using jQuery attr() to add the "target" attribute to links with class "external" and set the target to "_blank".

When I add code based on the lesson content I keep getting the feedback "Bummer! I was expecting target to be _blank not ``" despite passing both "target" and "_blank" to the attr() method in my answer (i.e., attr("target","_blank").

The Code Challenge actually returns this same feedback regardless of what strings or values are passed in and only changes if nothing is passed in at all. I won't attach the code since I don't want to give away the question, but it seems to be passing muster except for this one phantom issue.

2 Answers

Per Karlsson
Per Karlsson
12,683 Points

Hi Nathan,

It's hard to see where your error might be since you didn't provide any code :)

Anyway, here is the solution to the challenge:

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

Best of luck!

Andrew Miller
Andrew Miller
14,295 Points

Thanks Nathan,

question. What is the "target" within the HTML?

In the image gallery lesson we used $image.attr("src", imageLocation) and learnt that the .attr method is defined as .attr( attributeName, value ). Within the lesson I can see why src is the attributeName and where it is within the HTML, but I do not see target within the HTML for the challenge.

HTML for the challenge: <ul> <li><a href="http://google.com" class="external">Google</a></li> <li><a href="http://yahoo.com" class="external">Yahoo</a></li>

What am I missing or not understanding about the attributeName of the .attr method?

Thanks, Per. I did eventually come back to that response after having apparently entered it with a typo the first time round.

My question actually was about the quiz itself, not about the content. It seemed to be giving me the same error message no matter what mistake I made, even when I gave it a variety of different errors on purpose; usually I rely on the very helpful tips in the feedback to figure out what I'm doing wrong, so not having them was slowing me down.

Per Karlsson
Per Karlsson
12,683 Points

target is an attribute. What happens is that we add a new (or change if it exists) attribute to all the elements with the class external.

So the HTML output would look like this after the JavaScript code is executed.

<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>

Basically it means that when clicking on the links you'll open them up in a new, blank, browser window.

Hope this helps!

~Per

Andrew Miller
Andrew Miller
14,295 Points

Thanks! I did not know that target was an actual html attribute.