Hi, i have this code below. When it is loaded it shows a link with the text "Estado 1". When you click it, it should be replaced by another link with the text "Estado 2". When you click on "Estado 2" the link "Estado 1" should appear again and so on... <script type="text/javascript"> function cambio(){ var capa = document.getElementById("estado1"); if (capa.id == "estado1") { capa.innerHTML = <a href="#" onclick="cambio()">Estado 2</a>; capa.id = "estado2"; } else{ capa.innerHTML = <a href="#" onclick="cambio()">Estado 1</a>; capa.id = "estado1"; } //capa.innerHTML= (capa.style.display == "none") ? "block" : "none"; } </script> </head> <body> <div> <div id="estado1"> <a href="#" onclick="cambio()">Estado 1</a> </div> </div> HTML: My problem: after clicking "Estado 1" the sentence "Estado 2" is showed, but not as a link but as plain text.. Javi
1) Download jquery library (www.jquery.com) 2) http://docs.jquery.com/Effects - use any of these, takes 1 min. and 2 lines of code 3) Welcome to 2010
Here You Go :: <script type="text/javascript"> function cambio(){ var capa = document.getElementById("estado1"); if(capa == null) var capa = document.getElementById("estado2"); if (capa.id == "estado1") { capa.innerHTML= '<a href="#" onclick="cambio()">Estado 2</a>'; capa.id = "estado2"; } else{ capa.innerHTML = '<a href="#" onclick="cambio()">Estado 1</a>'; capa.id = "estado1"; } //capa.innerHTML= (capa.style.display == "none") ? "block" : "none"; } </script> </head> <body> <div> <div id="estado1"> <a href="#" onclick="cambio()">Estado 1</a> </div> </div> Code (markup):