for example, if i have:
<style>
.mystyle {background-color:#ff0000}
</style>
how can retrieve the background color for that style?
is there something like: document.mystyle.background-color (?)
thanks in advance.
alex.
alex bazan wrote:
> Is it possible to retrieve a property from a defined style in a style
> sheet?
>
> for example, if i have:
>
> <style>
> .mystyle {background-color:#ff0000}
> </style>
>
> how can retrieve the background color for that style?
In Netscape 6 and later, Mozilla, IE 4 and later there is a property
document.styleSheets
thus if you have exactly one embedded CSS stylesheet
<style type="text/css">
.mystyle {background-color:#ff0000}
</style>
you can access it as
var stylesheet = document.styleSheets ? document.styleSheets[0] : null;
then in Mozilla and other W3C DOM compliant browsers each sheet has a
property cssRules for the rules, in IE there is a property rules e.g.
if (stylesheet) {
var rules = stylesheet.cssRules ? stylesheet.cssRules :
stylesheet.rules;
the first (and only rule in your example) has the index 0 e.g.
if (rules && rules[0]) {
rules[0].style.backgroundColor = '#00ff00';
}
}
--
Martin Honnen
http://JavaScript.FAQTs.com/
Thanks, finally i got the right "googlequery" and found a script with a
similar code
(http://chapnickman.com/2005/03/14/get-style-sheet-values-with-javascript/)
At last, i opted for a PHP solution.
thaks for all.
alex.