• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

11. Managing Style Sheets > 11.12. Reading Effective Style Sheet Property Value...

Reading Effective Style Sheet Property Values

NN 6, IE 5

Problem

You want a script to ascertain the value of a style sheet property initially set via a <style> tag or imported style sheet.

Solution

The following getElementStyle( ) function works with browsers that support W3C DOM element referencing syntax, and either the IE currentStyle object or W3C DOM window.getComputedStyle( ) method:

function getElementStyle(elemID, IEStyleProp, CSSStyleProp) {
    var elem = document.getElementById(elemID);
    if (elem.currentStyle) {
        return elem.currentStyle[IEStyleProp];
    } else if (window.getComputedStyle) {
        var compStyle = window.getComputedStyle(elem, "");
        return compStyle.getPropertyValue(CSSStyleProp);
    }
    return "";
}

PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint