Robin Rodricks
Robin Rodricks

Reputation: 113996

What DOM manipulation can be done on Text nodes?

I'm going through the DOM using childNodes and I have a reference to a Text node, and I need to modify its "inner HTML" .. but I tried and it does not work or have such a property. Apart from replaceChild(), what functions can I use to manipulate the inner HTML of this Text node?

Upvotes: 0

Views: 711

Answers (2)

nickf
nickf

Reputation: 546085

The attribute you're probably looking for is called nodeValue. If you alter the nodeValue of a text node, that will change the text.

Upvotes: 1

jrista
jrista

Reputation: 32960

Text nodes are leaf nodes. They can not have any children, and they are simply plain old text. You can't and shouldn't edit them via inner html. All you should have to do is edit the value of a text node to change its contents. If you need to replace a text node with structured html, then you will need to remove the text node, and add the appropriate text, element, and attribute nodes in its place.

Upvotes: 1

Related Questions