# DOM 中的双生子
# textContent vs innerText
Difference between textContent vs innerText (opens new window)
- innerText是非标准的,textContent是较早标准化的。
- innerText返回节点中包含的可见textContent文本,而textContent返回全文。
- 因此,innerText它对性能的要求更高:它需要布局信息才能返回结果。
- innerText只为HTMLElement对象textContent定义,而为textContent所有Node对象定义。
例如,在以下 HTML <span>Hello <span style="display: none;">World</span></span>
中,innerText将返回“Hello”,而textContent将返回“Hello World”。