I'm working on a site where the content is being scraped from another site (both owned by same person). When it pulls in links, the href isn't formatted the way I need it to be, so I'm trying to preserve the original value and just add a slash to the beginning of it. I've gotten close, but can't get it to work properly. The current format is href="like-this"
, but I need it to be href="/like-this"
.
This what I've tried that came close:
$('.disamb li a').attr('href', function() {
return '/' + this.href;
});
That returns the whole absolute url with a / at the very beginning. So I tried using each()
:
$('.disamb li a').each(function() {
$(this).attr('href', '/'+this.href);
});
Same result. I tried a couple of other ways, but these two were the closest. How can I go about doing this without then running it through a replace function to strip it down to what I need? (that just seems sloppy)