Random Background Colour Picker For Tumblr
I've got this in my code, which should select a random background colour every refresh, but i can't see what's wrong with my document.write var bgcolorlist=new Array('#ff871b', '#
Solution 1:
You need semicolons after each line.
Additionally, why are you seeing the background color with a meta tag?
Use this line instead:
document.body.style.backgroundColor = bgcolorlist[Math.floor(Math.random()*bgcolorlist.length)];
Solution 2:
Another solution is to add an ID to your body and then use this code:
<script>var bgcolorlist=newArray("background: #ff871b", "background: #15efa1", "background: #51ddff", "background: #ff1b6c", "background: #000000");
var color = bgcolorlist[Math.floor(Math.random()*bgcolorlist.length)];
var d = document.getElementById("your-body");
d.setAttribute("style", color);
</script>
As far as I know, Tumblr allows you to use jQuery, which is way easier than pure Javascript. If you have jQuery added to your code, just do:
<script>var bgcolorlist=newArray("background: #ff871b", "background: #15efa1", "background: #51ddff", "background: #ff1b6c", "background: #000000");
var color = bgcolorlist[Math.floor(Math.random()*bgcolorlist.length)];
$('body').css('backgroundColor', color);
</script>
Post a Comment for "Random Background Colour Picker For Tumblr"