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

Anthony Sinclair
Anthony Sinclair
3,871 Points

How to set '_blank' rather than ' '

I am trying to simply add the attribute "target" with the value "_blank", but everything I try results in me getting a response that the program was expecting the value to be "_blank", not " ". Any help would be appreciated.

$("#cowbell").children(".external").attr("target", "_blank");
<!DOCTYPE html>
  <link rel="stylesheet" href="css/style.css" type="text/css" media="screen" title="no title" charset="utf-8">
  <title>Links Page</title>
  <ul id="cowbell">
    <li><a href="http://google.com" class="external">Google</a></li>
    <li><a href="http://yahoo.com" class="external">Yahoo</a></li>
  <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>

1 Answer

Jennifer Nordell
Jennifer Nordell
Treehouse Teacher

You're very close here! In fact, I think you may have overthought it a bit. I'm not sure where you got the cowbell ID from at all. I don't see it in the html in the challenge. It seems that you may have added it yourself. All you need to do is remove the cowbell and children part. Take a look:

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

This selects the class external and adds the target attribute with a value of "_blank". What this means is that when someone clicks on one of those links, the result will open in a new tab. Hope this helps! :smiley: