Created
May 12, 2017 21:45
-
-
Save sameerkumar18/833aff59b4fa6db0bc8634a12677351a to your computer and use it in GitHub Desktop.
This JS basically randomly changes the colour of the div element every time the webpage refreshes. Just made this because I couldn't find this on the internet. To make this run you need to add this to your HTML page "onload="return ran_col()" {For Example - <body onload="return ran_col()">}
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
| function ran_col() { //function name | |
| var color = '#'; // hexadecimal starting symbol | |
| var letters = ['7550FB','ff0000','66ff66','669900','9999ff','3366ff','990099','C0C0C0']; //Set your colors here | |
| color += letters[Math.floor(Math.random() * letters.length)]; | |
| document.getElementById('ENTER ELEMENT NAME').style.background = color; // Setting the random color on your div element. | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment