Aug 26, 2007

style, currentStyle, runtimeStyle

style reprensent the style attribute of an object. But think of it as javascript object. If an element has no style attribute defined, element.color will be undefined. currentStyle is IE object that attached to an element. In firefox it is not accessible.It is a read only object, so you can get the style no matter how the style is created(either from css style sheet or the style attribute of the object.) runtimeStyle is also IE proprietary object, it is meant to be used for write

            function getStyle(elem, name)
            {
            if (elem.style[name])
            {
            return elem.style[name];
            }
            else if (elem.currentStyle)
            {
            return elem.currentStyle[name];
            }
            else if (document.defaultView && document.defaultView.getComputedStyle)
            {
            name = name.replace(/([A-Z])/g,"-$1");
            name = name.toLowerCase();
            var s = document.defaultView.getComputedStyle(elem,"");
            return s && s.getPropertyValue(name);
            }
            else
            {
            return null;
            }
            }