Categories
JavaScript Answers

How to replace nbsp; from JavaScript DOM text node?

Spread the love

Sometimes, we want to replace from JavaScript DOM text node.

In this article, we’ll look at how to replace from JavaScript DOM text node.

How to replace from JavaScript DOM text node?

To replace from JavaScript DOM text node, we can use the string replace method.

For instance, we write

textNode.nodeValue = textNode.nodeValue.replace(/\u00a0/g, " ");

to call nodeValue.replace with /\u00a0/g and ' ' to replace all   characters with spaces in our text node.

Conclusion

To replace from JavaScript DOM text node, we can use the string replace method.

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 *