I am trying to generate 5 random hex colors using javascript. I got the output result too. I can able to print the random hex colors in <a></a>
element. But, I don't know how to print the same hex color value into background-color..
I have tried so far,
function returnMe() {
var s = "";
for(var i = 0; i < 5; i++) {
s += '<a class="a" href=""><span class="b">#' + (function co(lor){ return (lor +=
[0,1,2,3,4,5,6,7,8,9,'a','b','c','d','e','f'][Math.floor(Math.random()*16)])
&& (lor.length == 6) ? lor : co(lor); })('') + "</span><span class='c' style='background:'></span></a>";
}
document.getElementById("clr").innerHTML = s;
}
returnMe();
.a {
display: inline-block;
background: #fff;
border: 1px solid #e2e2e2;
width: 180px;
height: 180px;
margin: 10px;
text-align: center
}
.b {
background: #f9f9f9;
display: inline-block;
width: 100%;
padding: 10px 0
}
.c {
display: inline-block;
width: 100%;
height: 141px
}
<div id="clr">
</div>