Get Element style : HTML Style « HTML « JavaScript DHTML






Get Element style

<!-- 
     Example File From "JavaScript and DHTML Cookbook"
     Published by O'Reilly & Associates
     Copyright 2003 Danny Goodman
-->

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

           
       








Related examples in the same category

1.Paragraph Style
2.Make text bold by replaces it in the tree with an Element node
3.Using document create Style Sheet
4.Reading the canHaveChildren Property
5.Change the Text style Properties
6.Change html style
7.Using getBoundingClientRect()
8. Dynamically Updating Styles Using DHTML
9.'EM' and 'P' element