Home › Forums › JavaScript › How to replace all “../” href links with “/” › Re: How to replace all “../” href links with “/”
March 24, 2013 at 8:51 am
#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 ?