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

Preston Hill
Preston Hill
5,766 Points

Cant get passed this challenge.

I really don't understand how to do this.

js/app.js
$("external a").attr('target': '_blank');
index.html
<!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 id="target">
    <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

You are very close. The only thing is your not targeting the class. Ones you are targeting the class you don't need to also target the "a". This is your solution:

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

Hope this helps.

Preston Hill
Preston Hill
5,766 Points

Thank you so much. That worked perfectly.

SRIMUGAN J
PLUS
SRIMUGAN J
Courses Plus Student 5,345 Points

Hi, If you want to select the class put dot(.) before the class external in jquery like this $('.external') and also you added class external to directly to the anchor tag so to select the anchor tag class "external" is enough. And also if you want add attribute you should use comma in between property and its value like this $('.external').attr('target','_blank');

Don't forget to add your code between script tag.

Preston Hill
Preston Hill
5,766 Points

Thank you, that makes much more sense now.