/ Published in: JavaScript

fix for IE, adds getComputedStyle method for the object window and getPropertyValue method for the object, which returns getComputedStyle
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
if (!window.getComputedStyle) { window.getComputedStyle = function(el, pseudo) { this.el = el; this.getPropertyValue = function(prop) { var re = /(\-([a-z]){1})/g; if (prop == 'float') prop = 'styleFloat'; if (re.test(prop)) { prop = prop.replace(re, function () { return arguments[2].toUpperCase(); }); } return el.currentStyle[prop] ? el.currentStyle[prop] : null; } return this; } } EXAMPLE window.onload = function() { var compStyle = window.getComputedStyle(document.getElementById('test'), ""); alert(compStyle.getPropertyValue("color")); alert(compStyle.getPropertyValue("float")); alert(compStyle.getPropertyValue("background-color")); }
Comments
