1

<a class="test" href="www.abc.com?test1=1|6&test2=2">img</a> <a class="test" href="www.abc.com?test2=1&test3=2">img</a> <a class="test" href="www.abc.com?test3=1&test4=2">img</a>

I have a set of anchor elements with same class name, I need to extract a particular parameter, like test1 or test4, this value can be dynamic and update the href param with a new value

how do i do it in jquery?

any ideas?

1 Answers1

0
function getUrlParameter(sParam)
{
  $('.test').each( function() {
      var href= $(this).attr('href');
      //if href contain sParam ....... you should know that :) 
    );
 });
}​

String test1Param = getUrlParameter("test1");

Hope this help :)

taymedee
  • 484
  • 2
  • 5
  • 11
  • This gets the query parameter from the current page URL, not an `a` `href` attribute. – Felix Kling May 07 '14 at 02:10
  • @FelixKling is this what he want :) – taymedee May 07 '14 at 02:22
  • Nope, he wants the value of one of the parameters and update it, as it is written in the question: *"I need to extract a particular parameter, like test1 or test4, this value can be dynamic and update the href param with a new value"* – Felix Kling May 07 '14 at 02:24
  • @FelixKling Hm... what my posted is able to get the whole href attr string and update the new value by using basic javascript replace. Afterthat, update the href param with a new value by `$(this).attr('href') = //new replace href string`. I hope I am not misunderstanding this topic :( – taymedee May 07 '14 at 02:34
  • Sorry if i am not so clear, to give a more pratical example: i need to extract a dynamic value say 'test1' and replace it with '10' and update the href. – user3610392 May 07 '14 at 02:38