Frage

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

War es hilfreich?

Lösung

Try

$('a').attr('href', function(_, href){
    return href.replace(/^\.\./, '../additionalfolder')
})

Andere Tipps

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.

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);

});
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top