Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript How to replace all “../” href links with “/” Re: How to replace all “../” href links with “/”

#129515
Podders
Participant

Ahh yes it’s because the period character in regex represents any character, you can also escape that in the following way,

$(‘a’).each(function(){
$(this).attr(‘href’, function(index, old) {
return old.replace(new RegExp(/..//,’g’), ”);
});
});

New pen is here http://codepen.io/Podders/pen/lkBAC

Out of curiosity, why not just make all your links relative links to the root?, or do you not have control over the generated links ?