jQuery: How to use each starting at an index other than 0

Use slice() http://api.jquery.com/slice/

$('#someElemID').find('.someClass').slice(nextIndex).each( ...  

btw if the elements are static, consider caching:

var $elms = $('.someClass', '#someElemID'),
    nextIndex = 0;

for (var j = 1; j <= someCount; j++) {
    // do outside loop stuff

    $elms.slice(nextIndex).each(function(index) {
        if (/*this is right one*/) {
            nextIndex = index + 1; 
            return false;
        }
    });
}

That should improve performance considerably.

Leave a Comment