views:

134

answers:

2

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?

+1  A: 

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.

jrista
How do I "add the appropriate text, element, and attribute nodes in its place"?
Jenko
they're definitely not "plain old text". They are still DOM nodes which have a lot of properties.
nickf
@nickf: By "Plain old texT" I mean non-html. They are DOM, but text nodes can not have html structure...you need to replace the text node with text and html nodes to give it structure.
jrista
@nickf: Can I know which properties allow you to modify its inner HTML?
Jenko
+1  A: 

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

nickf