Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
61
rated 0 times [  64] [ 3]  / answers: 1 / hits: 99413  / 14 Years ago, wed, february 23, 2011, 12:00:00

Possible Duplicate:

Random Color generator in Javascript






I have some data I'd like to display in different colors and I want to generate the colors randomly if possible. How can I generate the Hex Color Code using JavaScript?


More From » javascript

 Answers
44

This will generate a random number within the bounds and convert it to hexadecimal. It is then padded with zeros so that it's always a valid six-digit hex code.



'#'+(Math.random() * 0xFFFFFF << 0).toString(16).padStart(6, '0');

[#93612] Tuesday, February 22, 2011, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
gideonb

Total Points: 187
Total Questions: 101
Total Answers: 86

Location: North Korea
Member since Mon, Feb 27, 2023
1 Year ago
;