How to replace text inside a div element?

Spread the love

Sometimes, we want to replace text inside a div element with JavaScript.

In this article, we’ll look at how to replace text inside a div element with JavaScript.

How to replace text inside a div element?

To replace text inside a div element with JavaScript, we set the textContent property.

For instance, we write

fieldNameElement.textContent = "New text";

to set the textContent property of the fieldNameElement div element to "New text" to set that as the text of the div.

Conclusion

To replace text inside a div element with JavaScript, we set the textContent property.

Leave a Reply

Your email address will not be published.