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
Fundamentals
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.
Concept
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.
Foundation
📝 Syntax
JavaScript
const all = textNode.wholeText;
Value
A string with the concatenated text of the adjacent Text run.
Rules
🔄 What Counts as “Adjacent”?
Situation
wholeText includes…
One lone Text child
Just that node’s text (same as data)
Two+ Text siblings in a row
All of them, in order
Text | Element | Text
Only 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.
Before normalize(), two nodes remain but wholeText already shows the combined string. After normalize, one Text node holds that string as data. See normalize().
Applications
🚀 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.
Under the Hood
🔧 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().
Important
📝 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.
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().
UniversalWidely available
Google ChromeFull support · Desktop & Mobile
Full support
Mozilla FirefoxFull support · Desktop & Mobile
Full support
Apple SafariFull support · macOS & iOS
Full support
Microsoft EdgeFull support · Chromium
Full support
OperaFull support · Modern versions
Full support
Internet ExplorerSupported in modern IE versions
Supported
wholeTextExcellent
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.
Wrap Up
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.
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
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about wholeText
Adjacent text runs as one string—tree unchanged.
5
Core concepts
📄01
Read-only
instance property
Kind
🔄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.