Saturday, April 13, 2024
 Popular · Latest · Hot · Upcoming
rated 0 times [  105] [ 6]  / answers: 1 / hits: 82796  / 15 Years ago, wed, march 25, 2009, 12:00:00

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

I specifically want to see if I can change the existing node, rather than creating a new one.

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

As answered below, content can be changed by setting the nodeValue property of these Objects.

More From » dom


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

node.nodeValue=new value;


innerText (and possibly textContent) will return/set both the current node and all descendent nodes text, and so may not be the behaviour you want/expect.

[#99798] Wednesday, March 18, 2009, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.

Total Points: 725
Total Questions: 85
Total Answers: 89

Location: Singapore
Member since Sat, Jul 25, 2020
4 Years ago