Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery reorder divs

Tags:

html

jquery

I have 3 divs want to reverse the order on doucment ready

<div id="block-1">First</div>
<div id="block-2">Second</div>
<div id="block-3">Third</div>

How can I do this in jquery?

like image 612
LeBlaireau Avatar asked Apr 10 '12 12:04

LeBlaireau


1 Answers

<div id="parent">
<div id="block-1">First</div>
<div id="block-2">Second</div>
<div id="block-3">Third</div>
</div>

And try this in Jquery

$('#parent > div').each(function() {
    $(this).prependTo(this.parentNode);
});​

You can see example in jsfiddle http://jsfiddle.net/N7PGW/

like image 155
Chuck Norris Avatar answered Oct 04 '22 15:10

Chuck Norris