-1

Possible Duplicate:
How to change the href for a hyperlink using jQuery

I have an anchor tag for which the href="" like so <a class="SwitchAccountLink" href=""></a>. I want to override this using jQuery and provide a different href. Is it possible to override the inline href of an anchor tag?

Thanks in advance.

Community
  • 1
  • 1
neelmeg
  • 2,459
  • 6
  • 34
  • 46

5 Answers5

2

You can use jquery attr() to get and set values of element attributes, more about attr() As your anchor tag has class which we will use to uniquely identify all the anchors with class SwitchAccountLink

$('.SwitchAccountLink').attr('href', 'Yourhref');
Adil
  • 146,340
  • 25
  • 209
  • 204
2

You can use jQuery's .attr() function to modify specific attributes of your elements.

$("a.SwitchAccountLink").attr('href',NEW_URL);

This code will replace all anchor tags with the SwitchAccountLink class with NEW_URL.

If you want to only change specific links, you might have to provide a more unique id attribute or an additional class that groups all the links.

Lix
  • 47,311
  • 12
  • 103
  • 131
1
$('.SwitchAccountLink').attr('href', 'http://www.google.com');

http://api.jquery.com/attr/

Brad
  • 159,648
  • 54
  • 349
  • 530
1

you can change it doing $(".SwitchAccountLink").attr('href','myNewHref');

Hugo Dozois
  • 8,147
  • 12
  • 54
  • 58
1

Sure, try:

$('.SwitchAccountLink').attr('href','someurl');
j08691
  • 204,283
  • 31
  • 260
  • 272