HTML Code:<html> <head> <title>Random Colors</title> <style type = "text/css"> body {color:red;} table {background:blue; border-style: solid; border-color: red;} </style> <script type = "text/javascript"> function randomColor(){ r = Math.round(Math.random() * 255); g = Math.round(Math.random() * 255); b = Math.round(Math.random() * 255); base = r / 16; rem = r % 16; base = base - (rem / 16); baseR = ConvertToHex(base); remR = ConvertToHex(rem); base = g / 16; rem = g % 16; base = base - (rem / 16); baseG = ConvertToHex(base); remG = ConvertToHex(rem); base = b / 16; rem = b % 16; base = base - (rem / 16); baseB = ConvertToHex(base); remB = ConvertToHex(rem); hexnum = '#' + baseR +remR + baseG + remG + baseB + remB; return hexnum; }//end randomColor function ConvertToHex(num) { if((num >= 0) && (num <= 9)) return num; else { switch(num) { case 10: return "A"; case 11: return "B"; case 12: return "C"; case 13: return "D"; case 14: return "E"; case 15: return "F"; }//end switch }//end else }//end ConvertToHex function changeTableColor(){ tblMain.style.borderColor = randomColor(); } function changeFontColor(){ tblMain.style.color = randomColor(); } </script> </head> <body onload = "changeFontColor();changeTableColor();"> <h1>Random Colors</h1> </ br> <table ID = "tblMain"> <tr><td>table cell</td></tr> </table> </body> </html>





Reply With Quote