JQuery .each() backwards JQuery .each() backwards arrays arrays

JQuery .each() backwards


$($("li").get().reverse()).each(function() { /* ... */ });


I present you with the cleanest way ever, in the form of the world's smallest jquery plugin:

jQuery.fn.reverse = [].reverse;

Usage:

$('jquery-selectors-go-here').reverse().each(function () {    //business as usual goes here});

-All credit to Michael Geary in his post here: http://www.mail-archive.com/discuss@jquery.com/msg04261.html


You can do

jQuery.fn.reverse = function() {    return this.pushStack(this.get().reverse(), arguments);}; 

followed by

$(selector).reverse().each(...)