/    Sign up×
Community /Pin to ProfileBookmark

Switching the text of a link

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…

[code=html] <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>[/code]

My problem: after clicking “Estado 1” the sentence “Estado 2” is showed, but not as a link but as plain text..

Javi

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@WebnerdJan 28.2010 — <i>
</i>function cambio(tag)
{
tag.firstChild.nodeValue = tag.firstChild.nodeValue == 'Estado 2' ? 'Estado 1' : 'Estado 2'
}



<i>
</i> &lt;div id="estado1"&gt;
&lt;a href="#" onclick="cambio(this)"&gt;Estado 1&lt;/a&gt;
&lt;/div&gt;
×

Success!

Help @tirengarfio spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.26,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...