generate rnadom color js code example
Example 1: javascript random color generator
function generateRandomColor() {
var letters = '0123456789ABCDEF';
var color = '#';
for (var i = 0; i < 6; i++) {
color += letters[Math.floor(Math.random() * 16)];
}
return color;
}
var randomColor=generateRandomColor();
Example 2: generate random color jquery
$("#btn").click(() => {
var colorCode = "1234567890abcdef";
var color = "";
for (var i = 0; i < 6; i++) {
color += colorCode.charAt(Math.floor(Math.random() * colorCode.length));
}
$("#hex").html("HEX: " + "#" + color);
$("#displaycolor").css("background", "#" + color);
});