Reputation: 219
I want to look through the entire page on a site and replace relative img paths with "/". For example:
$("body img").attr("src",function(){
return this.src.replace("uploads","/uploads");
});
However, in cases where the relative path could be different than whats above, I want to use regex to account for all the different scenarios. I know the images will all reside in the same location, but the various paths to replace could be "uploads, ../uploads, or ../../uploads, etc.
Any help would be appreciated..?
Upvotes: 0
Views: 814
Reputation: 2377
use this
$('img').each(function(){
$(this).attr('src',$(this).attr('src').replace(/^/,"/"));
$('body').append('<br />');
$('body').append($(this).attr('src'));
})
here is fiddle
Upvotes: 1