Skip to content

Instantly share code, notes, and snippets.

@joshrhoades
Created February 7, 2014 23:41
Show Gist options
  • Save joshrhoades/8874249 to your computer and use it in GitHub Desktop.
Save joshrhoades/8874249 to your computer and use it in GitHub Desktop.
IE8 polyfill/shim for supporting textContent (vs innerText) so that textContent is universally accessible. Can be embedded as a standalone script in a `[if lte IE 8]` embed.
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);
}
}
);
})();
}
@enricosoft
Copy link

Hi,
I've some problems using this polyfill... it seems that it causes problem with jQuery append\prepend functions.... is it possible?

@manngo
Copy link

manngo commented Oct 17, 2016

@enricosoft: Not surprising. I haven’t looked into it but it’s possible that jQuery modifies its behaviour depending on whether textContent exists. That shouldn’t matter, but sometimes people use one test to imply another (if it has textContent, then maybe it also has …). Alternatively, maybe this polyfill is missing something subtle.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment