JavaScript Text wholeText Property

Beginner
⏱️ 11 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Baseline Widely available
Instance property

What You’ll Learn

Text.wholeText is a read-only instance property that returns the concatenated string of this text node and every logically adjacent Text node, in document order. Learn how it differs from data, how it relates to normalize(), and when an element sibling breaks the run—with five examples and try-it labs.

01

Kind

Read-only property

02

Returns

String

03

Joins

Adjacent Text nodes

04

Order

Document order

05

Vs normalize

Read-only merge view

06

Status

Baseline widely

Introduction

A parent can hold several Text children in a row—for example after you remove a middle <strong> and two leftover text nodes sit next to each other. Each node still has its own data, but the visible sentence is really one run of characters.

wholeText lets you pick any text node in that run and read the full concatenated string without calling normalize() first.

JavaScript
console.log(textNode.wholeText); // all adjacent text as one string
💡
Beginner tip

MDN: this is similar to calling Node.normalize() and then reading the text value, but without modifying the tree. Your adjacent text nodes stay separate.

Understanding the Property

MDN: the read-only wholeText property of the Text interface returns the full text of all Text nodes logically adjacent to the node. The text is concatenated in document order.

  • Instance — read on one specific text node.
  • Read-only — you cannot assign to wholeText.
  • Adjacent — neighboring Text siblings (no element between them).
  • Includes self — this node’s text is part of the result.

📝 Syntax

JavaScript
const all = textNode.wholeText;

Value

A string with the concatenated text of the adjacent Text run.

🔄 What Counts as “Adjacent”?

SituationwholeText includes…
One lone Text childJust that node’s text (same as data)
Two+ Text siblings in a rowAll of them, in order
Text | Element | TextOnly the run on this side of the Element
Text inside <strong>That inner text only (not outer siblings)
📌
data vs wholeText

Use data (or nodeValue) when you care about one node. Use wholeText when you want the full unbroken text run around that node. For an entire element’s visible text including nested elements, prefer textContent.

⚡ Quick Reference

GoalCode
Read adjacent runtextNode.wholeText
This node onlytextNode.data
Merge nodes for realparent.normalize()
All descendant textelement.textContent
MDN statusBaseline Widely available (Jul 2015)

🔍 At a Glance

Four facts about Text.wholeText.

Kind
property

Read-only

Type
string

Concatenated

Scope
adjacent Text

Same parent run

Status
baseline

Widely available

Examples Gallery

Examples follow MDN Text.wholeText and everyday adjacent-text patterns.

📚 Getting Started

From one node to a run of siblings.

Example 1 — Single Text Node

With no neighbors, wholeText matches data.

JavaScript
const text = new Text("CodeToFun");
console.log(text.data);
console.log(text.wholeText);
console.log(text.data === text.wholeText);
Try It Yourself

How It Works

The adjacent run is just this one node, so both properties return the same string.

Example 2 — Two Adjacent Text Nodes

Append two text nodes; either one’s wholeText joins both.

JavaScript
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"
Try It Yourself

How It Works

data stays per-node. wholeText walks the adjacent Text run and concatenates in document order—same result from a or b.

📈 MDN Story, Breaks & normalize()

Where wholeText shines after DOM edits.

Example 3 — MDN-Style: Remove Middle Element

After deleting a middle element, leftover text siblings form one run.

JavaScript
const p = document.createElement("p");
p.appendChild(new Text("Through-hiking is great! "));
const strong = document.createElement("strong");
strong.textContent = "No filler!";
p.appendChild(strong);
p.appendChild(new Text(" However, keep hiking."));

p.removeChild(p.childNodes[1]); // remove 

console.log(p.childNodes.length); // 2 text nodes
console.log("'" + p.childNodes[0].wholeText + "'");
Try It Yourself

How It Works

Inspired by MDN’s paragraph demo: removing the middle element leaves adjacent text nodes; childNodes[0].wholeText reads both at once.

Example 4 — An Element Breaks the Run

Text on each side of an element does not share one wholeText.

JavaScript
const p = document.createElement("p");
const left = new Text("Before ");
const mid = document.createElement("em");
mid.textContent = "middle";
const right = new Text(" after");
p.append(left, mid, right);

console.log(left.wholeText);  // "Before "
console.log(right.wholeText); // " after"
console.log(p.textContent);   // "Before middle after"
Try It Yourself

How It Works

<em> splits adjacency. Use p.textContent when you need every descendant’s text together.

Example 5 — wholeText vs normalize()

wholeText reads the merge; normalize() actually merges nodes.

JavaScript
const div = document.createElement("div");
div.appendChild(new Text("Part 1 "));
div.appendChild(new Text("Part 2"));

const first = div.firstChild;
console.log(div.childNodes.length);     // 2
console.log(first.wholeText);           // "Part 1 Part 2"

div.normalize();
console.log(div.childNodes.length);     // 1
console.log(div.firstChild.data);       // "Part 1 Part 2"
Try It Yourself

How It Works

Before normalize(), two nodes remain but wholeText already shows the combined string. After normalize, one Text node holds that string as data. See normalize().

🚀 Common Use Cases

  • Reading leftover adjacent text after removing a middle element.
  • Inspecting text runs without calling normalize().
  • Debugging why childNodes lists more than one #text.
  • Comparing per-node data with the visible adjacent string.
  • Teaching the difference between sibling Text runs and full textContent.

🔧 How It Works

1

Start at this Text node

You read node.wholeText on one Text.

Start
2

Walk adjacent Text siblings

Include neighbors until an element (or end) stops the run.

Walk
3

Concatenate in document order

Earlier siblings first, then later ones.

Join
4

Return one string

Tree unchanged—unlike normalize().

📝 Notes

  • Baseline Widely available (MDN, since July 2015).
  • Not Deprecated, Experimental, or Non-standard — no status banner required.
  • Read-only — do not assign to wholeText.
  • Does not cross element boundaries in the sibling list.
  • Related: assignedSlot, Text(), normalize(), textContent, JavaScript hub.

Universal Browser Support

Text.wholeText is Baseline Widely available across modern browsers (MDN: since July 2015). Logos use the shared browser-image-sprite.png sprite from this project.

Baseline · Widely available

Text.wholeText

Read concatenated adjacent text nodes without calling normalize().

Universal Widely available
Google Chrome Full support · Desktop & Mobile
Full support
Mozilla Firefox Full support · Desktop & Mobile
Full support
Apple Safari Full support · macOS & iOS
Full support
Microsoft Edge Full support · Chromium
Full support
Opera Full support · Modern versions
Full support
Internet Explorer Supported in modern IE versions
Supported
wholeText Excellent

Bottom line: Use wholeText for adjacent Text runs; use data for one node; use textContent for all descendants; use normalize() to merge nodes for real.

Conclusion

text.wholeText returns the concatenated string of logically adjacent Text nodes without changing the DOM. Prefer data for one node, textContent for whole subtrees, and normalize() when you need a real merge.

Continue with splitText(), normalize(), textContent, or the JavaScript hub.

💡 Best Practices

✅ Do

  • Use wholeText after removals that leave adjacent text
  • Compare with data when debugging multi-node text
  • Call normalize() only when you want to merge for real
  • Use textContent for element-wide text including nested tags
  • Remember document order when reading the result

❌ Don’t

  • Assign to wholeText (it is read-only)
  • Expect it to include text inside neighboring elements
  • Confuse it with full-subtree textContent
  • Assume one text child after every HTML edit—check childNodes
  • Use normalize() just to read a combined string

Key Takeaways

Knowledge Unlocked

Five things to remember about wholeText

Adjacent text runs as one string—tree unchanged.

5
Core concepts
🔄 02

Concatenates

adjacent Text

Value
📌 03

vs data

one node vs run

Compare
⚖️ 04

vs normalize

read vs merge

DOM
🎯 05

Baseline

widely available

Status

❓ Frequently Asked Questions

A read-only string: the concatenated text of this Text node plus every Text node logically adjacent to it, in document order.
No. MDN marks Text.wholeText as Baseline Widely available (since July 2015). It is not Deprecated, Experimental, or Non-standard.
data (and nodeValue) is only this one text node’s content. wholeText joins neighboring text siblings too, so it can be longer than data when adjacent Text nodes exist.
MDN: wholeText is similar to calling Node.normalize() and then reading the text, but without modifying the tree. normalize() merges adjacent text nodes; wholeText only reads the combined string.
An Element (or other non-Text) sibling between text nodes. Text inside a <strong> or <a> is not adjacent to text outside that element for wholeText purposes.
No. It is read-only. To change text, assign to data / nodeValue / textContent, or rebuild nodes.
Did you know?

HTML parsers often create unexpected text nodes for whitespace between tags. Those nodes participate in adjacency too—so wholeText (and childNodes) can surprise beginners who only look at elements.

Next: Text.splitText()

Learn how to cut a text node at an offset into two siblings.

splitText() →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

5 people found this page helpful