Skip to content

Instantly share code, notes, and snippets.

@johnkpaul
Created February 10, 2012 16:42
Show Gist options
  • Save johnkpaul/1790727 to your computer and use it in GitHub Desktop.
Save johnkpaul/1790727 to your computer and use it in GitHub Desktop.
Shim for getComputedStyle in old IEs
(function(window, undefined){
window.getComputedStylePropertyValue = function(el,cssProperty){
if(!window.getComputedStyle){
if(document.defaultView && document.defaultView.getComputedStyle){
return document.defaultView.getComputedStyle.getPropertyValue(cssProperty);
}
else{
var camelCasedCssProperty = getCamelCasedCssProperty(cssProperty);
if(el.currentStyle){
return el.currentStyle(camelCasedCssProperty);
}
else{
return el.style[camelCasedCssProperty];
}
}
}
else{
return window.getComputedStyle(el).getPropertyValue(cssProperty);
}
}
function getCamelCasedCssProperty(cssProperty){
return cssProperty.replace(/-([a-z])/g, function (g) { return g[1].toUpperCase() });
}
})(this)
@pyrsmk
Copy link

pyrsmk commented Apr 16, 2014

Neat, but your polyfill does not return a computed style but the declared CSS one instead. I'll work for a better version ;)

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