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 “/”


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

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

New pen is here

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 ?