tags:

views:

57

answers:

3

I have the following configuration:

<div><div id='box1'>&nbsp;</div><div id='box2'>&nbsp;</div><div id='box3'>&nbsp;</div><div id='box4'>&nbsp;</div></div>

what i need to do is to invert the order of the divs

<div><div id='box4'>&nbsp;</div><div id='box3'>&nbsp;</div><div id='box2'>&nbsp;</div><div id='box1'>&nbsp;</div></div>

is there a fast way to do this with jQuery without cloning, removing and replacing the items?

+4  A: 

I guess you're looking for jQuery Reverse Order plugin.

Michal Čihař
thats a cool plugin. But i use this in my own plugin, i don't want to depend on a other one.
meo
i gonna use his code its pretty simple but effectife:function() { return this.each(function() { $(this).prependTo( $(this).parent() ); });};
meo
yes the code there is quite simple to include elsewhere...
Michal Čihař
A: 

You could use the jQuery TinySort plugin to order the items by class name (descending)...

http://plugins.jquery.com/project/TinySort

Sohnee
+2  A: 

Try this:

$top = $('div#thatTopDiv');
$top.children('div').slice(1).each(function() {
    $(this).insertBefore($top.children().eq(0));
});

Edit: Tested and this works.

nickf