<div class="grid">
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
</div>
const colors = [
'red', 'blue', 'magenta', 'green', 'yellow',
'aqua', 'brown', 'silver', 'lime'
];
for (let i = colors.length; --i > 0;) {
const j = Math.random() * (i + 1) | 0;
[ colors[i], colors[j] ] = [ colors[j], colors[i] ];
}
document.querySelectorAll('.item').forEach((n, i) => {
n.style.backgroundColor = colors[i];
});