I have been using this script to switch CSS background colour on click and I am trying to add a third colour option but can't seem to get it working. Can anyone help to get the third colour to work?
Here is my jsfiddle link:
https://jsfiddle.net/pkrWV/70/
var bodyObj, className, index;
bodyObj = document.getElementById('body');
index = 1;
className = [
'imageOne',
'imageTwo',
'imageThree',
];
function updateIndex(){
if(index === 0){
index = 1;
}else{
index = 0;
}
}
bodyObj.onclick = function(e){
e.currentTarget.className = className[index];
updateIndex();
}
Thanks,
James