Should be a simple while loop, appending an image and incrementing the count, until .error() is fired because the image doesn't exist.
The problem is the error event never fires. There are three images in the directory, but the page just loads indefinitely until the tab crashes. Calling .error() on an image in the html works, it's only when I append the image, then call error.
Code below:
jQuery(document).ready(function($) {
var images = 'load';
var i = 1;
while(images == 'load') {
$('.images').append('<img src="window_0' + i + '.jpg" />')
.error(function() {
images = 'finished';
});
i++;
}
});
If I use while(i<4) it works perfectly, as the result of .error() doesn't matter. The thing is I need this to be variable so that the number of images loaded can be increased by just adding files to the directory without editing the code.
This used to be possible with an ajax call but doesn't work in my version of jQuery (1.7.1