JavaScript moving element in the DOM

Let’s say I have three <div> elements on a page. How can I swap positions of the first and third <div>? jQuery is fine.


Trivial with jQuery


If you want to do it repeatedly, you’ll need to use different selectors since the divs will retain their ids as they are moved around.

$(function() {
    setInterval( function() {
    }, 3000 );

Source: stackoverflow