user105033 user105033 - 4 months ago 10
HTML Question

How do I change the text of a span element in JavaScript

If I have a span, say:

<span id="myspan"> hereismytext </span>


How do I use JavaScript to change "hereismytext" to "newtext"?

Answer
document.getElementById("myspan").innerHTML="newtext";

EDIT For modern browsers :

document.getElementById("myspan").textContent="newtext";
Comments