Categories
JavaScript Answers

How to change text node value with JavaScript?

Spread the love

Sometimes, we want to change text node value with JavaScript.

In this article, we’ll look at how to change text node value with JavaScript.

How to change text node value with JavaScript?

To change text node value with JavaScript, we can set the nodeValue property.

For instance, we write

node.nodeValue = "new value";

to set the text node‘s nodeValue to a string.

Setting nodeValue will only set the value of the text node and not affect descending nodes.

Conclusion

To change text node value with JavaScript, we can set the nodeValue property.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *