is it possible to iterate through elements from last to first one? For example from the last parent ul in a list to the nearest parent-ul one. At the moment I use each() but it would be nice to change direction...
Thanks!
You can use the reverse() method on Arrays
https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/reverse
$($("ul li").get().reverse()).each(function(){ });
or create your own function:
jQuery.fn.reverse = function() {
return this.pushStack(this.get().reverse());
};
$("ul li").reverse().each(function(){ });
working example: http://jsfiddle.net/hunter/kdREt/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With