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

Jason Brown
Jason Brown
9,626 Points

I guess I don't understand what they're asking for ?

I followed the example from the previous lesson. I'm not sure what I'm doing wrong? I feel like I misunderstood the question, maybe? Thanks.

js/app.js
$(".external li").click(function(event) {
  event.preventDefault();
  var target = $(this).attr("target");
  $links.attr("_blank", target)
});
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>
Abraham Juliot
Abraham Juliot
47,353 Points

Where is $links declared and assigned?

2 Answers

Jason, According to the question asked by the challenge you need to add the attribute 'target' to each link with class="external". Using jQuery only I would use the $('selector').each(function(){}); function and then add the target attribute to each element. Pseudo code could look like this: GET each ".external" $"this external".attr("target", "_blank");

Read for .each(): http://api.jquery.com/each/ Read for .attr(): http://api.jquery.com/attr/

Steven Parker
Steven Parker
231,275 Points

You may have linked to the wrong challenge.

The challenge I see following the "view challenge" button above says Challenge Task 1 of 1 Using jQuery only, add to all links with the class "external", the target attribute with the value of "_blank".

But your code shows the creation of a click event handler. Either the link is pointing to the wrong challenge, or your code is doing things that are not related to the challenge.