두 innerText및 textContent모든 2016 년 기준으로 표준화 Node(순수 텍스트 노드 포함) 개체를 가지고 textContent있지만 HTMLElement개체가 있습니다 innerText.
textContent대부분의 브라우저에서 작동 하지만 IE8 이전 버전에서는 작동하지 않습니다. 이 polyfill을 사용하여 IE8에서만 작동하십시오. 이 polyfill은 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 이상에서 사용할 수 있지만 DOM 객체에 대해서만 IE8에서 사용할 수 있습니다.
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