jquery each last to first code example
Example 1: jquery loop through collection backwards
$($("li").get().reverse()).each(function() { /* ... */ });
Example 2: jquery each check if last index
var total = $('ul li').length;
$('ul li').each(function(index) {
if (index === total - 1) {
// this is the last one
}
});