Javascript examples for DOM HTML Element:Div
Random color for <div> text
<html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <script type="text/javascript"> window.onload=function(){//www . j a v a 2 s . c o m var array_ofcolors = ['red', 'blue','orange'] var obj = document.getElementById('foo'); obj.style.color = array_ofcolors[Math.floor(Math.random()*array_ofcolors.length)] } </script> </head> <body> <div id="foo"> THIS IS A TEST </div> </body> </html>