replace part of link

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • FrEaKmAn
    New Member
    • Aug 2007
    • 46

    replace part of link

    Hello,

    I'm using jquery but I think this could be done with pure javascript. I have links like

    [HTML]<div id="statisticst ype">
    <a href="#statisti cs/day/type:songs">Son gs</a>
    <a href="#statisti cs/day/type:albums">Al bums</a>
    </div>[/HTML]

    now before this I have an option to set range (day,month,year ). Now could I replace only "day" with something else?
  • nomad
    Recognized Expert Contributor
    • Mar 2007
    • 664

    #2
    Originally posted by FrEaKmAn
    Hello,

    I'm using jquery but I think this could be done with pure javascript. I have links like

    [HTML]<div id="statisticst ype">
    <a href="#statisti cs/day/type:songs">Son gs</a>
    <a href="#statisti cs/day/type:albums">Al bums</a>
    </div>[/HTML]

    now before this I have an option to set range (day,month,year ). Now could I replace only "day" with something else?

    day is part of the path. so if you change day to year you will need to have a folder called year.

    nomad

    Comment

    • FrEaKmAn
      New Member
      • Aug 2007
      • 46

      #3
      Originally posted by nomad
      day is part of the path. so if you change day to year you will need to have a folder called year.

      nomad
      it's not important if I'm gonna have folder or not. What I want is to change the value of href, for example

      from

      Code:
      #statistics/day/type:songs
      to

      Code:
      #statistics/year/type:songs
      there could be also more options after type:songs so this need to stay untouched...

      Comment

      • rnd me
        Recognized Expert Contributor
        • Jun 2007
        • 427

        #4
        Originally posted by nomad
        day is part of the path. so if you change day to year you will need to have a folder called year.

        nomad
        not true.

        notice the hash (#).

        these HREFs refer to a location on the current page, and thus the same file and folder.


        at any rate, here is code to replace all of them:
        Code:
        var allAs =  document.getElementsByTagName("a");
        var mx= allAs.length;
        for(var i = 0; i< mx; i++){
           var it = allAs[i];
           it.href = it.href.toString().replace(/day/g, "year" )
        }

        Comment

        • FrEaKmAn
          New Member
          • Aug 2007
          • 46

          #5
          this is possible, but when we replace it once we can't replace it with something else, so is it possible to make a pattern?

          Comment

          Working...