I have the following piece of JS which toggles the BG color from red to green and so on.
function blink() {
var currentColor = 'red';
setInterval(function () {
document.body.style.backgroundColor = currentColor;
currentColor = currentColor === 'red' ? 'green' : 'red';
}, 1000);
};
Is there anyway to change the colours to images so it toggles between two images instead of two colours?
I have tried the following but without success:
function toggleBG() {
var currentColor = "Images/tableBGRed.gif";
setInterval(function () {
var myDiv = document.getElementById("testDiv");
myDiv.style.backgroundImage = "url('" + currentColor + "')";
currentColor = currentColor === "url('Images/tableBGRed.gif')" ? "url('Images/tableBG.gif')" : "url('Images/tableBGRed.gif')";
}, 1000);
};
Something wrong with the syntax?