The div below is element x
. The text node in the div
is element y
.
These tests are about text nodes, which are also called data.
y.appendData(' An extra text.'); alert(y.data);
The first test should return undefined
, since x
is
not a text node.
alert(x.data)
alert(y.data)
y.data = 'A new sentence takes the place of the old.'
y.deleteData(4,3); alert(y.data);
y.insertData(4,' inserted data '); alert(y.data);
y.replaceData(4,12,' replaced data '); alert(y.data);
alert(y.substringData(4,12));
First split the text, then normalize it.
alert('Before: ' + x.firstChild.nodeValue); y.splitText(10); alert('After: ' + x.firstChild.nodeValue);
alert('Before: ' + x.firstChild.nodeValue); x.normalize(); alert('After: ' + x.firstChild.nodeValue);
Split the text node first; wholeText
should still give you the entire text.
alert(y.wholeText)
y.wholeText = "Let's change it!"
y.wholeText = "Let's <u>change</u> it!"