最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to retrieve the text of a DOM Text node? - Stack Overflow

programmeradmin4浏览0评论

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

  • textContent
  • data
  • nodeValue
  • wholeText

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?)

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

  • textContent
  • data
  • nodeValue
  • wholeText

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?)

Share Improve this question edited Sep 1, 2019 at 0:53 user719662 asked Oct 7, 2011 at 17:17 Šime VidasŠime Vidas 186k65 gold badges287 silver badges391 bronze badges 0
Add a ment  | 

2 Answers 2

Reset to default 11

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

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

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

发布评论

评论列表(0)

  1. 暂无评论