To Find all elements with class "box" + x:
for (var x = 0; x <= 9999; x++) {
if ($('.box' + x).length < 1) {
$('.box' + x).addClass('yourClass');
} else {
break;
}
}
This assumes you wont have box x if you don't have box (x-1). (boxes are numbered in order without any missing numbers) If this assumption is not correct, let me know.