Skip to content

Instantly share code, notes, and snippets.

@sameerkumar18
Created May 12, 2017 21:45
Show Gist options
  • Select an option

  • Save sameerkumar18/833aff59b4fa6db0bc8634a12677351a to your computer and use it in GitHub Desktop.

Select an option

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()">}
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