Change the value of textNode

Is there a way to change the DOM value of textNode in a web browser?

I specifically want to see if I can modify an existing node, and not create a new one.

To clarify, I need to do this using Javascript. All text in the browser is stored in #textNodes, which are child nodes of other HTML nodes but cannot have child nodes.

As shown below, the contents can be changed by setting the nodeValue property of these objects.

+60
javascript dom dhtml
Mar 25 '09 at 6:25
source share
2 answers

If you have a specific node (type #text) and want to change its value, you can use the nodeValue property

node.nodeValue="new value"; 

Note:

innerText (and possibly textContent) will return / set both the current text node and all subsequent nodes, and maybe this will not be the behavior you want / expect.

+91
Mar 25 '09 at 6:37
source share

I believe that innerHTML is used for this ... And again, this is not W3C endorsement ... but it works ...

 node.innerHTML="new value"; 
-four
Mar 25 '09 at 6:32
source share



All Articles