Должно быть что-то вроде:
// Gets the number of elements with class yourClass
var numItems = $('.yourclass').length
Как примечание, часто полезно проверять свойство длины, прежде чем связывать много вызовов функций в объекте jQuery, чтобы убедиться, что у нас действительно есть какая-то работа. Смотрите ниже:
var $items = $('.myclass');
// Ensure we have at least one element in $items before setting up animations
// and other resource intensive tasks.
if($items.length)
{
$items.animate(/* */)
// It might also be appropriate to check that we have 2 or more
// elements returned by the filter-call before animating this subset of
// items.
.filter(':odd')
.animate(/* */)
.end()
.promise()
.then(function () {
$items.addClass('all-done');
});
}