<html>
<head>
<style type="text/css">
#magic_div {
padding: 20px;
display: inline-block;
background-color: yellow;
}
</style>
<script type="text/javascript">
function colorIt(){
var colorName = "rgb("+(Math.random()*255).toFixed()+","+(Math.random()*255).toFixed()+","+(Math.random()*255).toFixed()+")";
document.getElementById('magic_div').style.backgroundColor = colorName;
}
window.onload = function(){
setInterval("colorIt()",400);
};
</script>
</head>
<body>
<div id="magic_div"></div>
</body>
</html>
|
Demo & Output
|