(e-mail address removed) wrote :
Is there a way to change the background color dynamically, when the
color is defined at a CSS stylesheet?
(tried document.bgcolor and this.style.background-color)
Thanks
Assuming this is your stylesheet declaration:
<style type="text/css">
body {color: black; background-color: white;}
</style>
and that you want to change the background-color to silver,
then:
if(document.styleSheets && document.styleSheets[0].cssRules)
// DOM 2 Stylesheets compliant
{
document.styleSheets[0].cssRules[0].style.backgroundColor = "silver";
}
else if(document.styleSheets && document.styleSheets[0].rules)
// IE specific
{
document.styleSheets[0].rules[0].style.backgroundColor = "silver";
};
W3C DOM 2 Style sheet: Attribute styleSheetshttp://
www.w3.org/TR/2000/REC-DOM-Level-2-Style-20001113/stylesheets....
W3C DOM 2 CSS: Attribute cssRuleshttp://
www.w3.org/TR/2000/REC-DOM-Level-2-Style-20001113/css.html#CSS...
Gérard