I have picture links that are stored in a array, and I change the background of a div using those picture links when a button is clicked.
So far everything is ok, but I don't understand how can I make the function return the first value of array ([0]) when the i value is greater than the array.length value.
Here's what I got:
function palabifunkcija(){
document.getElementById('PictureContent').value= ++i;
document.getElementById('PictureContent').style.background= bildes[i];
if (i>bildes.length){
return i=0;
}
}
Clicking makes the pictures change, but when the if statement executes, i have to click twice on the button and it displays 2nd picture (bildes[1]) not bildes[0].
Can anyone explain why it's so and how can I fix it, so it works properly?
Sorry for the bad english.