0

I have many database rows that used relative url with one directory up.

How do i change this relative url:

<a href="../somefolder"></a>

to

<a href="../additionalfolder/somefolder"></a>

FYI: I use jQuery 1.2.6

Wildan Muhlis
  • 1,553
  • 2
  • 22
  • 43
  • http://stackoverflow.com/a/4314050/1355315 – Abhitalks Dec 12 '13 at 05:05
  • 1
    For your own sake, please upgrade your version of jQuery – Ian Dec 12 '13 at 05:07
  • 1
    At first glance, this task seems really easy to achieve. I'm surprised you didn't find a solution by yourself. Did you try something? Are there particular constraints making this problem complex? –  Dec 12 '13 at 05:59
  • @wared yes, it's just newbie question :) – Wildan Muhlis Dec 12 '13 at 09:27
  • @WildanMuhlis A newbie who do not know Google (http://api.jquery.com/attr/)? I'm joking :D Keep enjoying :) –  Dec 12 '13 at 09:29

3 Answers3

1

Try

$('a').attr('href', function(_, href){
    return href.replace(/^\.\./, '../additionalfolder')
})
Arun P Johny
  • 384,651
  • 66
  • 527
  • 531
0

Hope this is the output you expect?

 $(function(){
   var $a =$('a');
     var OldUrl =   $a.attr('href');
     var newUrl = OldUrl.replace("../","../additionalfolder/");         
      $a.attr('href', newUrl);

});
Krish R
  • 22,583
  • 7
  • 50
  • 59
0

this might help you

var strUrl = window.location.protocol + "//" + window.location.host + "/";

this will give you the root folder path now you can concate your database path to this.

Sohil Desai
  • 2,940
  • 5
  • 23
  • 35