I need to iterate over jquery child elements in reverse:
$("#parent").children().each(function() {
# do stuff
})
but in reverse.
I have seen the use of reverse() with get()
$($("li").get().reverse()).each(function() { /* ... */ });
but don't seem able to make it work with children().
Using the same strategy as before:
$($("#parent").children().get().reverse()).each(function() {
# do stuff
})
Or slightly more neatly:
[].reverse.call($("#parent").children()).each(function() {
# do stuff
})
try this
jQuery.fn.reverse = [].reverse;
$("#parent").children().reverse().each(function () {
});
SEE HERE
How about
$.each( $("#parent").children().get().reverse(), function(){
// whatever..
} );
Demo at http://jsfiddle.net/mPsep/
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