The HTML elements’ position are determined in a linked CSS.
div.title
{
position:absolute;
top:12px;
}
I can only use document.styleSheets[0].cssRules[0].position to find the value of the position of the title, but how can I know this position belongs to the title?
In other word, how can the js code know the document.styleSheets[0].cssRules[0] is for the title?
There are a few browser differences when getting styles. To get a style rule generically:
If you just want to match the first rule of the first sheet, then:
and to see the selector:
and to see the styles that have been set:
Noting that some browsers will return exactly what is written in the style sheet and others will return their interpretation of that (i.e. it is implementation dependent and can’t be directly compared across browsers).