When I click on an image it should be adding it to an array, however the max lenght of the array is 6, therefore if there are already 6 objects in the array it should alert and stop letting the user click on any new image.
When I run the following I can keep adding images and the alert never happens.
jQuery('body').on('change', '.masonry .item :checkbox', function () {
var urls = [];
urls.length = 6;
if (jQuery(urls.length > 6)) {
alert("Puoi aggiungere un massimo di 6 immagini");
} else {
jQuery('.masonry .item :checkbox:checked').each(function () {
urls.push(jQuery(this).next('label').find('img').attr('src'));
});
}
});
jQuery(urls.length > 6)This will be something like$(false)or$(true)var urls = [];urls.lengthwould do itif (jQuery(urls.length > 6)) {should be justif (urls.length > 6) {!