Ambos innerText& textContentsão padronizados a partir de 2016. Todos os Nodeobjetos (incluindo os nós de texto puro) têm textContent, mas apenas HTMLElementobjetos têm innerText.
Embora textContentfuncione com a maioria dos navegadores, ele não funciona no IE8 ou anterior. Use esse polyfill para funcionar apenas no IE8. Esse polyfill não funcionará com o IE7 ou anterior.
if (Object.defineProperty
&& Object.getOwnPropertyDescriptor
&& Object.getOwnPropertyDescriptor(Element.prototype, "textContent")
&& !Object.getOwnPropertyDescriptor(Element.prototype, "textContent").get) {
(function() {
var innerText = Object.getOwnPropertyDescriptor(Element.prototype, "innerText");
Object.defineProperty(Element.prototype, "textContent",
{
get: function() {
return innerText.get.call(this);
},
set: function(s) {
return innerText.set.call(this, s);
}
}
);
})();
}
o Object.defineProperty método está disponível no IE9 ou superior, no entanto, está disponível no IE8 apenas para objetos DOM.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty
https://developer.mozilla.org/en-US/docs/Web/API/Node/textContent