If innerHTML is evil, then what's a better way change the text of a link?
Posted
by sanj
on Stack Overflow
See other posts from Stack Overflow
or by sanj
Published on 2008-12-27T14:40:35Z
Indexed on
2010/03/08
11:06 UTC
Read the original article
Hit count: 193
I know innerHTML is supposedly evil, but I think it's the simplest way to change link text. For example:
<a id="mylink" href="">click me</a>
In JS you can change the text with:
document.getElementById("mylink").innerHTML = new_text;
And in Prototype/jQuery:
$("mylink").innerHTML = new_text;
works fine. Otherwise you have to replace all of the child nodes first and then add a text node. Why bother?
© Stack Overflow or respective owner