Skip to content

Javascript Jquery loop through elements forward and backward

Qutaiba Rawashdeh edited this page Apr 13, 2015 · 1 revision

Forward

$('#form-signup').find('.pets').each(function ( ) {
    if($(this).hasClass('hide')) {
        $(this).removeClass('hide');
        return false;
    }
});

In Revers

$($('#form-signup').find('.pets').get()).reverse().each(function ( ) {
    if($(this).attr('id') === "pet1") return false;
    if(!$(this).hasClass('hide')) {
        $(this).addClass('hide');
        return false;
    }
});

$.fn.reverse = [].reverse;