Amira Manai
Amira Manai

Reputation: 2599

putting a variable into a css button's href attribute

I want to affect a variable containing url to a css button's href attribute i tried location.href but it didn't work .

here's my button description :

             <div>
          <p><a id="gameNextLevel" class="button"  href="">Next</a></p>
      </div>

Here's my JSF related code :

            var uiNextLevel = $("gameNextLevel");
            matchingGame.savingObject.currentLevel="game6.html";

                uiNextLevel.click(function(e) {
                e.preventDefault();
                                // location.href = "login.html";
                 location.href =  matchingGame.savingObject.currentLevel;  

                });

Any idea please , Thank you in advance :)

Upvotes: 3

Views: 548

Answers (2)

Marko
Marko

Reputation: 10992

 uiNextLevel.click(function(e) {
                e.preventDefault();

                $(this).attr("href") =  matchingGame.savingObject.currentLevel;  

                });

Upvotes: 2

Joseph
Joseph

Reputation: 119867

You missed the hash # in the selector, which means id

var uiNextLevel = $("#gameNextLevel");

also, for "dead links", use a hash # also in the href.

<a id="gameNextLevel" class="button"  href="#">Next</a>

Upvotes: 3

Related Questions