Created
February 7, 2014 23:41
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} | |
); | |
})(); | |
} |
Hi,
I've some problems using this polyfill... it seems that it causes problem with jQuery append\prepend functions.... is it possible?
@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
For those interested, I put together a more complete shim, which addresses some of the more subtle problems of the "innerText substitution" solution. It's included in aight. Enjoy!