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 Introduction to jQuery Hello, jQuery! Accessing and Modifying Attributes

Help with attar

I'm trying to open all links that are not part of my root domain on a new tab. Here's my code:

//get all the the site links that are not part of our website to open in a new tab
$('a').not("href^='file:///C:/Users/'") //select all the links that are not part of our root domain
    .attr('target', '_blank'); //open then in new tab

I'm not sure how to get the bit inside the .not() to work properly. Any suggestions?

1 Answer

Umesh Ravji
Umesh Ravji
42,386 Points
$('a').not("[href^='file:///C:/Users/']").attr('target', '_blank');

You're missing the square brackets from your css selector.

Thanks Umesh. Appreciate the help.