jQuery('.msnf-form-step').each(function() { if (jQuery('li:nth-child(2)').hasClass('active')) { jQuery('.active').prevAll().addClass('finished'); } if (jQuery('li:nth-child(3)').hasClass('active')) { jQuery('.active').prevAll().addClass('finished'); } if (jQuery('li:nth-child(4)').hasClass('active')) { jQuery('.active').prevAll().addClass('finished'); } if (jQuery('li:nth-child(5)').hasClass('active')) { jQuery('.active').prevAll().addClass('finished'); } if (jQuery('li:last-child').hasClass('active')) { jQuery('.active').prevAll().addClass('finished'); } });
Вы можете просто выбрать .active элемент
jQuery('li.active')
Так что вам нужно только
jQuery('li.active').prevAll().addClass('finished');
Не могли бы вы объяснить, почему вам нужен каждый цикл ()?
jQuery('.msnf-form-step').each(function() { // });