Created
March 7, 2009 08:30
-
-
Save slant/75274 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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