Šime Vidas
Šime Vidas

Reputation: 185883

How to retrieve the text of a DOM Text node?

For a given Text node in the DOM, one can use one of these properties to retrieve its text:

But which one to use? Which one is the most reliable and cross-browser supported?

(If multiple properties are 100% reliable and cross-browser, then which one would be most appropriate?)

Upvotes: 25

Views: 4938

Answers (2)

Felix Kling
Felix Kling

Reputation: 816312

nodeValue should be is cross-browser compatible. It is part of the original DOM Level 2 specification.

Also have a look at the compatibility table of quirksmode.org for that matter (that's what I always use to see which properties are supported by which browsers).

Upvotes: 11

Aron Woost
Aron Woost

Reputation: 20658

When you're 100% sure that it's a text node you can use any of them.

Upvotes: -1

Related Questions