jquery: reverse an order

laukok picture laukok · Jun 2, 2011 · Viewed 30.4k times · Source

How can I reverse an order with jquery?

I tried with the suggestion like this but it won't work!

$($(".block-item").get().reverse()).each(function() { /* ... */ });

Have a look here.

I want the boxed to be rearranged like this,

18
17
16
etc

Thanks.

Answer

Jamie Treworgy picture Jamie Treworgy · Jun 2, 2011

If you have a container around the list, it's a little easier:

$("#container").append($(".block-item").get().reverse());

http://jsfiddle.net/BhTEN/12/