Skip to content

Instantly share code, notes, and snippets.

@eligrey
Created August 26, 2009 17:17
Show Gist options
  • Save eligrey/175652 to your computer and use it in GitHub Desktop.
Save eligrey/175652 to your computer and use it in GitHub Desktop.
/*
* 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
}
);
}());
}
@usmonster
Copy link

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 or enumerable 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 to true. 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 )

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