Wednesday, February 5, 2014

Generate Random Colors using javascript

<script type="text/javascript">
        // Run function for every second of timer
        setInterval(rgbcolors, 1000);

        function getrgbcolors() {
            // rgb string generation
            var col = "rgb("
+ Math.floor(Math.random() * 255) + ","
+ Math.floor(Math.random() * 255) + ","
+ Math.floor(Math.random() * 255) + ")";
            //change the text color with the new random color
            document.getElementById("stylediv").style.color = col;
        }

 </script>


<div id="stylediv" >Generate Random Colors using javascript</div>

No comments:

Post a Comment