Random background color and text (Pure JS)
HTML
<div class="monobg">
<img src="http://chloesilver.ca/mono1.png" />
</div>
<p class="legend">Some text</p>
CSS
.blue {
color: blue;
}
.monobg {
background-color: red;
padding:10px;
width:60px;
}
.blue .monobg {
background: blue;
}
.red {
color: red;
}
.red .monobg {
background: red;
}
.green {
color: green;
}
.green .monobg {
background: green;
}
JavaScript
function setColor() {
var colors = [" red", " green", " blue"],
css = colors[Math.floor(Math.random() * colors.length)];
document.querySelector("body").className = document.querySelector("body").className + css;
}
window.addEventListener("load", setColor);