Return to Snippet

Revision: 12777
at March 28, 2009 01:52 by Jman


Updated Code
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"));
}

Revision: 12776
at March 28, 2009 01:49 by Jman


Initial Code
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;
    }
}

Initial URL


Initial Description
fix for IE, adds getComputedStyle method for the object window and getPropertyValue method for the object, which returns getComputedStyle

Initial Title
getComputedStyle for IE

Initial Tags
css, javascript, DOM

Initial Language
JavaScript