Adding a variable to the href attribute of a css button

I want to affect a variable containing url on the href attribute of the css button, which I tried location.href, but that didn't work.

here is the description of my button:

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

Here is 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 thanks in advance :)

+3
source share
2 answers

You missed the hash #in the selector, which meansid

var uiNextLevel = $("#gameNextLevel");

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

<a id="gameNextLevel" class="button"  href="#">Next</a>
+3
source
 uiNextLevel.click(function(e) {
                e.preventDefault();

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

                });
+2
source

All Articles