poner una variable en el atributo href de un botón css
Frecuentes
Visto 517 veces
3
Quiero afectar una variable que contiene url al atributo href de un botón css. Probé location.href pero no funcionó.
aquí está la descripción de mi botón:
<div>
<p><a id="gameNextLevel" class="button" href="">Next</a></p>
</div>
Aquí está mi código relacionado con JSF:
var uiNextLevel = $("gameNextLevel");
matchingGame.savingObject.currentLevel="game6.html";
uiNextLevel.click(function(e) {
e.preventDefault();
// location.href = "login.html";
location.href = matchingGame.savingObject.currentLevel;
});
Cualquier idea por favor, gracias de antemano :)
2 Respuestas
3
Te perdiste el hachís #
en el selector, lo que significa id
var uiNextLevel = $("#gameNextLevel");
también, para "enlaces muertos", use un hash #
también en el href
.
<a id="gameNextLevel" class="button" href="#">Next</a>
contestado el 03 de mayo de 12 a las 09:05
2
uiNextLevel.click(function(e) {
e.preventDefault();
$(this).attr("href") = matchingGame.savingObject.currentLevel;
});
contestado el 03 de mayo de 12 a las 09:05
No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas javascript css html or haz tu propia pregunta.