How to change the text of a span element using JavaScript?

Spread the love

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 set the innerHTML propert of it.

For instance, we write

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

to select the span with getElementById.

Then we set its innerHTML property to the content we want.

Conclusion

To change the text of a span element using JavaScript, we set the innerHTML propert of it.

Leave a Reply

Your email address will not be published.