Saturday, October 11, 2008

Get Computed Style Attribute

when a dom style has been setted more than one times in css file, the final style should be computed, such as:
css file:

#abc{
color: red;
}

div #abc{
color: red;
}

html file:
...

<div><span id='abc'>text in span...</span></div>
...

js code:

var spanEl = document.getElementById('abc');
var ret = document.defaultView.getComputedStyle( spanEl, null );
var color = ret.getPropertyValue("color");

so we can get the right style which appled to dom.

No comments: