How do I move div after its next div

How do I move a div after its next div. For instance I have 3 different div sitting here.

<div class="div1">Div1</div>
<div class="div2">Div2</div>
<div class="div3">Div3</div>

I wan to move first div after the second div. It means div2 will be first and div1 will be second. I have bunch of same html format.

I want to execute jquery something like

$(".div1").each(function() {
    $(this).appendTo().$(this).after();
});

Let me know if this doesn't make sense.

Answers


you can get the .next() element, and place it .after()

or

you can .insertAfter() the .next() element

http://jsfiddle.net/kFTc5/1/

$(".div1").each(function() {
    var item = $(this);

    //either this:
    item.next().after(item);

    //or this:
    item.insertAfter(item.next());


});

Need Your Help

How to achieve transaction-like behavior for non-database operations?

c# .net transactions

Suppose I have a database table with a list of file paths/URLs of the form &lt;fileID&gt;&lt;location&gt;, e.g.:

How to get last point of each dash-line created after CGContextSetLineDash of a CGPath

ios core-graphics cgpath

I am converting the path into dashline to get multiple segments of a CGPATH.