I'm making a colourful website and I want to change the background color of some div's at random, everytime someone load a new page. It's easy to change the body background when I reload, but the background color of the footer doesn't change.
I've got the same problem with the background-images. I need a way to change these at random. Probably with a script?
I've seen lots of scripts which uses document.write, but how do I write a stylesheet with document.write? Or is there a better solution than document.write?
I tried unsuccesfully:
<script type="text/javascript">
<!--
var imgAry = new Array('black','white','blue','yellow')
var randomNumber = Math.floor(Math.random()*4);
document.open();
document.write("<style type=text/css>footer {background-color: +imgAry[randomNumber]+ ;}</style>");
//-->
</script>
May be it's just the coding, may be someone knows a solution.document.write is javascript. You can't generate random variables with CSS because it is not a scripting language. You could use the DOM to alter your document though. Just ask about it in the javascript forum. One other method could be to use server side scripting.make "footer": ".footer" or "#footer" depending on if you use it as a class or id
I've got the same problem with the background-images. I need a way to change these at random. Probably with a script?
I've seen lots of scripts which uses document.write, but how do I write a stylesheet with document.write? Or is there a better solution than document.write?
I tried unsuccesfully:
<script type="text/javascript">
<!--
var imgAry = new Array('black','white','blue','yellow')
var randomNumber = Math.floor(Math.random()*4);
document.open();
document.write("<style type=text/css>footer {background-color: +imgAry[randomNumber]+ ;}</style>");
//-->
</script>
May be it's just the coding, may be someone knows a solution.document.write is javascript. You can't generate random variables with CSS because it is not a scripting language. You could use the DOM to alter your document though. Just ask about it in the javascript forum. One other method could be to use server side scripting.make "footer": ".footer" or "#footer" depending on if you use it as a class or id