I'm trying to write a function which cycles background-image
from 3 different options by button-click, and the code is not working. Maybe someone can tell why...
function changeBackground (){
console.log('change background');
var b = document.getElementById('mainbody');
var bstyle = window.getComputedStyle(b, null).getPropertyValue('background-image');
if (bstyle == "url('strawberry.png')") {
b.style.backgroundImage = "url('raspberry.png')";
} else if (bstyle == "url('raspberry.png')"){
b.style.backgroundImage = "url('blueberry.png')";
} else {
b.style.backgroundImage = "url('strawberry.png')";
}
}
For example, this code for changing font-size
works perfectly.
function changeSize (){
console.log('changing font size');
var s = document.getElementById('clock');
var sstyle = window.getComputedStyle(s, null).getPropertyValue('font-size');
if (sstyle == "25px") {
s.style.fontSize = "50px";
} else{
s.style.fontSize = "25px";
}
}