I did a test myself and got the following to work without problem. The div with id foo turns up red as expected. The js error message indicates you have not used the correct id when trying to find the element (the element can't be found and hence is null)...
<DIV id=foo>Yada yada</DIV>
document.getElementById("foo").style.backgroundColor = "red";
(Editreason: remove junk code... )
The message i get is getElemenbtby(...) is null or somthing like that. I thougt this should work. Not the easist question to answer whats wrong but a few tips would be greatly appreciated.