find a location for property in a new city

Friday, 11 January 2013

Add rel="nofollow" to all external links with one line of jQuery

You may want to change all external links on a page to do something different such as add a target="_blank" to each one or add rel="nofollow" to every external link. This post will show you how this can be done in one line of jQuery!

SEO SEO SEO... How tiresome a concept... Anyway, people make their living with it apparently and while that is the case I get all kinds of weird requirements like this. This time I had to add rel="nofollow" to all external links for latest whim of an SEO consultant.

Since SEO requirements seem to chop and change fairly unpredictably I wanted to add rel="nofollow" to all external links in the quickest and least interfering way possible. I managed it with one line of jQuery so that is fairly innocuous and I can just remove it if it needs to be undone at some point. This can be used to add target="blank" to also.

Add rel="nofollow" to all external links

$("div.content a[href^='http']:not([href*=''])").attr("rel", "follow");

Add target="_blank" to all external links

$("div.content a[href^='http']:not([href*=''])").attr("target", "_blank");

Hope this helps you spend as little time on this as possible :)


I did some reasearch into whether adding a nofollow in this way will work on Google and came to the conclusion that it probably wont. Colin Asquith commented similar thoughts. So this should probably be considered if using this for adding rel="nofollow" to links but technically this is a good way of going about it or anything similar like adding target="_blank" for example.

Follow britishdev on Twitter


  1. But doesn't this just add "nofollow" to links using JavaScript after the page has loaded? When a bot spiders your page it will actually get the links before they have had this attribute added, so will be treated as normal links.

    Basically if you have a website, and it's built up some credibility, sites you link out to get some of that - so often you want to use "nofollow" for something like a comments page so when people add links in comments they aren't doing it for their own SEO benefit.

    1. You know what? I think you're on to something. I actually looked into this myself as you can never be sure how Google works since it apparently does execute JavaScript. I came to the definitive solution that it *probably* wont work in the way I intended. As in it will affect the DOM but it will *probably* be too late for Google to care.

      However, I forgot I wrote a blog post about it so I should probably correct that.

  2. Also- a pleasure to see a .NET/SQL blog by a fellow developer and a fellow Colin :) we're taking over.

  3. I am pleased to read about no follow link,i have got useful information.I will come back to read more articles.
    gym mats are flexible buy them from

  4. Game online a lot of people who love to help them relieve stress of the moment, such as Tiny Tanks and Tiny Planes or Tiny Planes Beta is the fighting game with a pen or pencil, you have to destroy opponents before they kill you. Or Run 3 Unblocked and Hacked unblocked Gamesare skillful game controller for bears to dance to the goal without falling off a cliff. I wish you happy gaming!

  5. I Will Provide SEO Blog Comment Service . & niche relevant blog comment service we provide a quality service with 100% Buyer satisfaction and My team Believed in Quality work not Quantity Contact me Now 24/7.check out this Blog for your business . your business will be gain 200% more profit I can not recommend you guys enough.

  6. I have got useful information,thanks for sharing.
    golden slot
    gclub casino

  7. I was very impressed by this post, this site has always been pleasant news. Thank you very much for such an interesting post. Keep working, great job! In my free time, I like play game: What about you?

  8. Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a Front end developer learn from Javascript Training in Chennai . or learn thru JavaScript Online Training India. Nowadays JavaScript has tons of job opportunities on various vertical industry.

  9. a pride for me to be able to discuss on a quality website because I just learned to make an article on
    cara menggugurkan kandungan

  10. I've talked a lot about anchor text lately in terms of how important it is to vary up the anchor text which you use when creating links to your site.url shortener for twitter

  11. Motifz Designer Lawn. 1, 2 & 3 Piece Unstitched Premium Embroidered Lawn 2019, Premium Lawn, Lawn 2019, Best lawn collection, Motifz, Best Lawn in Pakistan, Shipping worldwide. Stitching option available.

  12. Buy Premium lawn Online for Women's at best prices available at Motifz. ✓ Latest Fashion, ✓ Trendy Designs ➤ Shop Now!

  13. This website and I conceive this internet site is really informative ! Keep on putting up!

  14. Coffee Grinders & Espresso Makers Prices in United State as on 26-Jul-2016. Find Latest Models, Best Prices, Genuine Products ninja coffee bar system, Top Brands and Stores for Coffee .

  15. Nothing compares to Weber using Genesis sort of grills. That is certainly the type gas grills which have been that will always make sure that they deliver a high performance part of down interval event coordinator companies

  16. I like viewing web sites which comprehend the price of delivering the excellent useful resource free of charge. I truly adored reading your posting. Thank you! mankhatri885

  17. Wow… all design is superb and attractive. I loved them. Thank you for sharing this blog online. Great Designs ever. We also provide stitch gold embroidery designs.For this you can get your membership today.

  18. Nothing compares to Weber using Genesis sort of grills. That is certainly the type gas grills which have been that will always make sure that they deliver a high performance part of down interval alinshop buy domestic USA