Keduanya innerText& textContentdistandarisasi pada 2016. Semua Nodeobjek (termasuk node teks murni) miliki textContent, tetapi hanya HTMLElementobjek yang memilikinya innerText.
Sementara textContentbekerja dengan sebagian besar browser, itu tidak berfungsi pada IE8 atau sebelumnya. Gunakan polyfill ini untuk hanya bekerja pada IE8. Polyfill ini tidak akan berfungsi dengan IE7 atau yang lebih lama.
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);
}
}
);
})();
}
The Object.definePropertymetode adalah availabe di IE9 atau naik, namun tersedia di IE8 untuk DOM objek saja.
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