How to change HTML link's href property dynamically

Hi I have a HTML link on my MVC3 View.

I want to change its href property each time user clicks it.

<a class="tabs" href="#educationDetails">
<input id="SubmitBtn" type="submit" value="Next" />

Is there any way to solve this issue.

Many Thanks


$(".tabs").click(function() {


you can get attribute value like this,

$(this).attr("href")  //will return '#educationDetails'

so you can check that value like this,

$(".tabs").click(function() {
  if ($(this).attr("href") == "#tab1")
  else if ($(this).attr("href") == "#tab2")


If you just want to change #tab1 to #tab2, not reverse. you can also do it like this way,

$('a.tabs[href="#tab1"]')​.click(function() {

$("a.tabs").click(function() {
    this.href = 'newhref';
    return false;

It is more efficient this way compared to @ocanal solution.


Need Your Help

Gridview programmatic tooltips using dictionary

c# dictionary key

I have the following code that I think should work - however, what I think and what actually works is something completely different! This being demonstrated by the fact it doesn't work!

Left Navigation won't expand to 100% Magento

magento css

I am working on a Magento store at: