views:

132

answers:

2

Hi,

I want to change the param of link dynamically.

For e.g.

  1. Link1
  2. Link2
  3. Link3

by default their url is ?item=text i.e. for link1(href="?item=link1") etc.. but when i click link1 the url of link2 and link3 should be link2(?item=link2&item=link1) link3(?item=link3&item=link1)

any idea how to acheive this?

Thanks,

A: 

Invoke jQuery something like the following:

$("my#links").attr("href", "new/href/value");

You'll need to write a function to calculate the new value of href for each link, of course.

Drew Wills
TSSS22
If it’s meant to work how you describe, then none of these links will ever do anything other than add their query strings to each other. None of them will actually get followed. Should they only do the query string manipulation on the first go, or something?
Paul D. Waite
+2  A: 

Assuming all the links have a class of superspeciallink, this should work:

$('a.superspeciallink').bind('click', function(){
    var querystring = this.search; // The search property of links gives you the querystring section of their href
    var originalhref = this.href;

    $('a.superspeciallink').each(function(){
        if(this.href != originalhref) {
            this.href = this.href + '&' + querystring.slice(1);
        }
    });

    return false;
});

This would mean that these links never get followed though — I assume some other JavaScript would be reading out these query string values eventually.

Paul D. Waite
this seems to be a nice approach I need to check this but in my case all the links are of same class. And actually its the method to filter the things .Yah you are rite its adding just query string one on to another but this is adding filters .....
TSSS22
Paul D. Waite