I want to change 5 or more images, on button click. I created some code, but cannot understand why it doesn't work. You can find my code here(I want to change images on the 2 picture):
var images = [
'img/tent1.png',
'img/tent2.png',
'img/tent3.png',
'img/tent4.png',
'img/tent5.png',
'img/tent6.png'
],
i=1;
for (var j = images.length; j--;) {
var img = new Image();
img.src = images[j];
}
$("#change").click('click', function (e) {
$('#awnings').attr('src', images[i >= images.length - 1 ? i = 0 : ++i]);
e.preventDefault();
});
http://jsfiddle.net/4Lzypuze/2/
Any thoughts? Thank you for your help.