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 trialnagamani palamuthi
6,160 Pointsthis challenge is not passing...
$(".external a").attr("target" , " _blank");
could someone chk my code?
$(".external a").attr("target" , " _blank");
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="css/style.css" type="text/css" media="screen" title="no title" charset="utf-8">
<title>Links Page</title>
</head>
<body>
<h1>Links</h1>
<ul>
<li><a href="http://google.com" class="external">Google</a></li>
<li><a href="http://yahoo.com" class="external">Yahoo</a></li>
</ul>
<script src="//code.jquery.com/jquery-1.11.0.min.js" type="text/javascript" charset="utf-8"></script>
<script src="js/app.js" type="text/javascript" charset="utf-8"></script>
</body>
</html>
2 Answers
Jennifer Nordell
Treehouse TeacherHi there! There are a couple of things going on here. First, you have an extraneous space between the quotation marks and the _blank
. Also, you are targeting all anchor tags inside of the class "external" instead of targeting all links that have the class "external". This is a subtle but important point.
There are two separate solutions that will pass this challenge, but I think maybe you can get it working with just these hints. Let me know if you're still stuck!
nagamani palamuthi
6,160 PointsThanks Jennifer got it! so selecting (".external a") targets all links in class external and ("a .external") targets any links with class .external? just clarifying..
Jennifer Nordell
Treehouse TeacherThat's correct!
Amir Eskandari
9,153 PointsAmir Eskandari
9,153 PointsGreat answer Jennifer, very helpful!
nagamani palamuthi
6,160 Pointsnagamani palamuthi
6,160 Pointsya great answer jennifer.. now it works. i fixed the space and just included the class name as selector. but I have a couple of doubts.
Thanks again for your time and help. Hope my questions make sense.
Jennifer Nordell
Treehouse TeacherJennifer Nordell
Treehouse TeacherHi! Glad you got through the challenge. The subtle difference I was referring to is not the difference between anchor tags and links. Those are the same thing.
The difference I was referring to is selecting something inside something else that has a class and selecting something that has that class name. Let's take a look at an example of what I mean.
Selecting "external" will select the div and then those rules will apply to everything inside. But the challenge wanted you to select something that has the class "external". So in the above example, the div has the class "external" and the links simply reside inside that parent container. But what they wanted was for you to target the links that have the class "external".
But if we did this:
It would select only the first link as that's the only one that now has the class "external". The other solution was to do this:
$("a.external").attr("target" , "_blank");
This is a very specific rule and specifically targets only anchor tags that have the class external assigned to them. Hope that clarifies things!
edited for additional note
Yes, this challenge is sort of odd in that the only things with the class "external" are the links. But if we'd had say a div or paragraph with that class then this is how you'd pick just the anchor tags that have "external" while leaving the div/paragraph alone