दोनों innerTextऔर textContent2016 के रूप में मानकीकृत हैं। सभी Nodeवस्तुओं (शुद्ध पाठ नोड सहित) textContent, लेकिन केवल HTMLElementऑब्जेक्ट हैं innerText।
textContentअधिकांश ब्राउज़रों के साथ काम करते समय , यह IE8 या इससे पहले काम नहीं करता है। केवल IE8 पर काम करने के लिए इस पॉलीफ़िल का उपयोग करें। यह पॉलीफ़िल IE7 या इससे पहले के साथ काम नहीं करेगा।
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);
}
}
);
})();
}
यह Object.definePropertyविधि IE9 या इसके बाद के संस्करण में उपलब्ध है, हालांकि यह IE8 में केवल 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