Is there any way to change the value of DOM textNode in a web browser?
I specifically wanted to see if I could change an existing node, rather than create a new node.
To clarify, I need to use Javascript to accomplish this. All text in the browser is stored in #textNodes, which are children of other HTML nodes but cannot have children of their own.
As Ash answered below, the content can be changed by setting the nodeValue property of these objects.
P粉9869374572023-10-18 18:44:07
I believe innerHTML is used for this purpose... then again, this is not W3C approved... but it works...
node.innerHTML="new value";
P粉4810352322023-10-18 12:22:23
If you have a specific node (#text type) and want to change its value, you can use the nodeValue attribute:
node.nodeValue="new value";
Notice:
innerText (and possibly textContent) will return/set the current node and all descendant node text, so may not be the behavior you want/expect.