Of all these I'd choose data
: it is defined for the nodes implementing CharacterData interface (Text and Comment ones) only. Trying to access this property for the others gives undefined
.
nodeValue is essentially the same as data
for text nodes, but is actually defined for attribute and comment nodes as well. And I usually want my programs to fail early. )
textContent is, for me, something completely different, as it represents the text content of a node and its descendants. This, along with wholeText, perhaps should be used more to collect texts from more complex structures than a single text node.
Said all that, textContent
and wholeText
were defined in DOM Level 3 (= more modern).