2g*****@gmail.com 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 styleSheets
http://www.w3.org/TR/2000/REC-DOM-Le...-DocumentStyle
W3C DOM 2 CSS: Attribute cssRules
http://www.w3.org/TR/2000/REC-DOM-Le...Sheet-cssRules
Gérard
--
Using Web Standards in your Web Pages (Updated Dec. 2006)
http://developer.mozilla.org/en/docs...your_Web_Pages