简体   繁体   中英

adding rel=“external” to every link

Hi I need to add rel="external" to every link () on my site is this possible?

so far i have tried $(".content a").attr("rel","external”);

I would add them manually but it is a 1000 page site and don't really want to code it on every link

thanks in advance

If you want it on all your links then you have to iterate through all of them and change that attribute

$(function () {
  $('a').each(function () {
    $(this).attr('rel', 'external');
  });
});

If your intent is to change every link within the element with class content then what you have should properly change it just wrap it in the function

$(function () {
  $('.content a').each(function () {
    $(this).attr('rel', 'external');
  });
});

Inspect the links in this jsfiddle to see that the attr has been added to those existing links http://jsfiddle.net/4d06xb0x/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM