JavaScript TextNode update
if I have
var t = document.createTextNode(text)
parent.appendChild(t);
Can I just update the content t
?
I would like to change the text inside parent
without using removeChild
, createTextNode
and appendChild
. Why would I need this and not just using it innerHTML
? As I do not want to update the content of the element with HTML code, but text
may contain special characters like <or and which must be parsed by TextNode
DOM methods .
Thanks
Tom
source to share
Keep in mind that adjacent text nodes are collapsed into one (since it is actually impossible to distinguish between two adjacent text nodes).
The content of the text node can be updated using the property nodeValue
(see MDC ).
Since the text node by this very definition cannot contain any markup, there is no property innerHTML
.
source to share
If you save an instance of the TextNode object (t in your example code), you can change the content using various functions like replaceData (), substringData (), etc.
See this page for reference: http://msdn.microsoft.com/en-us/library/ms535905(VS.85).aspx#
source to share