Hey guys, I found the following awesome script to create a random color with javascript.
var randColor = '#'+(Math.random()*0xFFFFFF<<0).toString(16);
the only problem with this script is that it does not guarantee that it returns a normal hexadecimal string with 7digit.
sometimes it's just 6 digits, like # e1d19.
is there any way to force a 7 digit hexadecimal value?
Thank you for your help.
edit: this is my actual problem:
function randColor() {
var randColor = '#'+(Math.random()*0xFFFFFF<<0).toString(16);
return randColor;
}
for (var i=0; i<100; i++) {
$("#colorpicker").append("<div class='color' title="+randColor()+" style='background:"+randColor()+"'></div>");
}
I create small divs with random colors, when I click on them, I grab their title attribute, and I color the background of my body.
however, currently my code ends in
<div style="background:rgb(176, 249, 252);" title="#8bc47d" class="color"></div>
so when I get the title attribute, the color that I give to my body is different from a small div show.