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

Deanna Campbell
Deanna Campbell
2,653 Points

$("a .external").attr("target" , "_blank"); supposed to add attr target & value _blank, but challenge says this is wrong

The error message says "I was expecting 'target' to be '_blank', not ' '." So the value is an empty string instead. How do I fix this?

js/app.js
$("a .external").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>
    <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>
Umesh Ravji
Umesh Ravji
42,386 Points

I would just like to add, "a .external" will target children of any a elements that have the class external given to them, where "a.external" will target any a elements that have the class external given too them (incase the space was intentional).

1 Answer

Umesh Ravji
Umesh Ravji
42,386 Points

Hi Deanna, the space between a and .external is your problem here.