Example 1 — Two Adjacent Text Nodes
Either sibling’s wholeText joins both; data stays per node.
const p = document.createElement("p");
const a = new Text("Hello ");
const b = new Text("World");
p.appendChild(a);
p.appendChild(b);
console.log(p.childNodes.length); // 2
console.log(a.data); // "Hello "
console.log(a.wholeText); // "Hello World"
console.log(b.wholeText); // "Hello World" How It Works
- Create two text nodes. Append
"Hello "and"World"as siblings under<p>. - Count children.
childNodes.lengthis2— they are still separate nodes. - Read data.
a.datais only the first node:"Hello ". - Read wholeText. From
aorb, you get the full run:"Hello World".

