Skip to content

Instantly share code, notes, and snippets.

@slant
Created March 7, 2009 08:30
Show Gist options
  • Save slant/75274 to your computer and use it in GitHub Desktop.
Save slant/75274 to your computer and use it in GitHub Desktop.
<html>
<head>
<script type="text/javascript">
function fill_boxes() {
random_color('box1');
random_color('box2');
}
function random_color(element) {
var rgb = generate_rgb();
document.getElementById(element).style.backgroundColor = rgb;
}
function generate_rgb() {
var rgb = "#";
var hex = ["0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F"];
for( i=1; i<=6; i++ ) { rgb += hex[ Math.floor(Math.random() * hex.length) ]; }
return rgb;
}
</script>
</head>
<body onload="fill_boxes();">
<div id="box1" style="margin-top: 10px; height: 100px; width: 100px;"></div>
<div id="box2" style="margin-top: 10px; height: 100px; width: 100px;"></div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment