InnerText alternative in mozilla [duplicate]

耗尽温柔 提交于 2019-11-29 13:21:48
alex

innerText is a proprietary IE thing. The W3C defines textContent as the official property.

An easy way is to exploit the || logical operator and its short circuiting nature, as well as JavaScript returning the last evaluated value in a condition (most times the truthy operand).

var body = document.body,
    text = body.textContent || body.innerText;

jsFiddle.

(Note in the fiddle I checked for the innerText first. This was only because most people on here do not use IE. IRL, check for textContent first, and fallback to innerText.)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!