JQuery .each() backwards

前端 未结 11 1073
萌比男神i
萌比男神i 2020-11-22 13:44

I\'m using JQuery to select some elements on a page and then move them around in the DOM. The problem I\'m having is I need to select all the elements in the reverse order t

11条回答
  •  清酒与你
    2020-11-22 14:25

    I prefer creating a reverse plug-in eg

    jQuery.fn.reverse = function(fn) {       
       var i = this.length;
    
       while(i--) {
           fn.call(this[i], i, this[i])
       }
    };
    

    Usage eg:

    $('#product-panel > div').reverse(function(i, e) {
        alert(i);
        alert(e);
    });
    

提交回复
热议问题