Replace domain on all href attributes


/ Published in: JavaScript
Save to your folder(s)



Copy this code and paste it in your HTML
  1. var linkRewriter = function(old_domain, new_domain) {
  2. $('a[href*="' + old_domain + '"]').each(function() {
  3. if ($(this).attr('href') == old_domain ) {
  4. $(this).attr('href', $(this).attr('href').replace(old_domain, new_domain));
  5. }
  6. });
  7. };
  8.  
  9. linkRewriter('www.olddomain.com', 'www.newdomain.com');

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.