Sometimes, we want to change the text of a span element using JavaScript.
In this article, we’ll look at how to change the text of a span element using JavaScript.
How to change the text of a span element using JavaScript?
To change the text of a span element using JavaScript, we change its textContent
property.
For instance, we write
document.getElementById("myspan").textContent = "new text";
to select the span with getElementById
.
Then we set its textContent
property to change the text.
Conclusion
To change the text of a span element using JavaScript, we change its textContent
property.