Posted By

odenijs on 10/21/11


Tagged

javascript replace jquery domain href


Versions (?)

Replace domain on all href attributes


 / Published in: JavaScript
 

  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  

You need to login to post a comment.