I want to make it so when ever I reload the page, the background gets chosen randomly.
function switchBG(urlThing) {
document.getElementById("bg-img").style.display="block";
document.getElementById("bg-img").style.backgroundImage="url(urlThing)";
}
var n = Math.floor((Math.random() * 2) + 1);
if (n == 1) {
switchBG('back1.jpg');
}
else if (n == 2) {
switchBG('back2.jpg')
}
I tried that, but nothing happened.
Edit: This is the div. It's the first thing under the tag.
<div id="bg-img"></div>