Created
August 26, 2009 17:17
-
-
Save eligrey/175652 to your computer and use it in GitHub Desktop.
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
/* | |
* textcontent.js | |
* 2010-07-21 | |
* By Eli Grey, http://eligrey.com | |
* | |
* Public Domain. | |
* NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK. | |
* | |
* Implements the element.textContent accessor in IE8. | |
*/ | |
if (Object.defineProperty && Object.getOwnPropertyDescriptor && | |
!Object.getOwnPropertyDescriptor(Element.prototype, "textContent").get) { | |
(function() { | |
var innerText = Object.getOwnPropertyDescriptor(Element.prototype, "innerText"); | |
Object.defineProperty(Element.prototype, "textContent", | |
{ | |
// It won't work in IE8 for some reason if you just drop | |
// in innerText.get and innerText.set or the whole descriptor. | |
get: function () { | |
return innerText.get.call(this) | |
} | |
,set: function (text) { | |
return innerText.set.call(this, text) | |
} | |
,configurable: true | |
,enumerable: true | |
} | |
); | |
}()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi @eligrey. I had a question about this shim vs. the one in your blog post from 2009. Is there any reason you would include or omit the
configurable
orenumerable
attributes?It seems they are not actually used in IE8 (according to MSDN--see the "Requirements" section), though I've also heard it will throw an error in IE8 if you set
enumerable
totrue
. I'm just wondering if the blog version omits those attributes for this reason, or if the version here includes them as an afterthought?(Please see also my fork: https://gist.github.com/usmonster/d15e4475e3983bd35dba )