Hi there,
I have a bunch of links on a page that on an action, I run a function and it appends an extra variable like so:
function storeId(uID) {
$('a.special').each(function(){
$(this).attr('href',$(this).attr('href')+'&variable='+uID+'');
});
}
My understanding is, the above would go through each link identified, and grab the existing href, then append the variable bits onto the end. I have got the variable appending, but its not working as expected... e.g its appending the '&variable=' part twice, the first time, like '&variable=undefined' and then on top of that '&variable=23'.
Is there a better way to do this? Or a way I can just say go through each of these links and simply update the value that is set to the variable rather than rewriting the whole href?
So just to re-iterate, my original link is just something like this:
<a class="special" href="/page.php?random=1">link name</a>
And the aim is to have it look like the following after the function is performed:
<a class="special" href="/page.php?random=1&variable=32">link name</a>
But it winds up looking like:
<a class="special" href="/page.php?random=1&variable=undefined&variable=32">link name</a>