tags:

views:

57

answers:

2

Hi,

In the below code, I get the two dialog boxes, but the bgColor of the page is never changed. Is there any standard that font / color changes are not honored in JavaScript ?

 <html>
<head>
</head>

<body bgColor="GRAY">
<script type="text/javascript">
document.write("This message is written by JavaScript");
alert('Am here');
alert('Am here again');
document.bgcolor="WHITE";
</script>
</body>

</html>
+3  A: 

bgColor is really, really old. Better use CSS values. And you need to address the body element, not the document.

This should work: document.body.style.backgroundColor = '#ffffff'

Pekka
Awesome. I got this from a new book and was wondering how come this didnt work. I tried in Chrome, IE and FF. Thanks for this.
Icarus
+1  A: 

That's because it's bgColor and not bgcolor (note the case).

Also, using document.body.style.backgroundColor might be a better idea. And I would use hexadecimal instead of named colors :)

So, use #ffffff instead of WHITE.

WoLpH