Let\'s say I have three There's no need to use a library for such a trivial task: This takes account of the fact that You could also use: and there are various other possible permutations, if you feel like experimenting: for example :-)
var divs = document.getElementsByTagName("div"); // order: first, second, third
divs[2].parentNode.insertBefore(divs[2], divs[0]); // order: third, first, second
divs[2].parentNode.insertBefore(divs[2], divs[1]); // order: third, second, first
getElementsByTagName
returns a live NodeList that is automatically updated to reflect the order of the elements in the DOM as they are manipulated.var divs = document.getElementsByTagName("div"); // order: first, second, third
divs[0].parentNode.appendChild(divs[0]); // order: second, third, first
divs[1].parentNode.insertBefore(divs[0], divs[1]); // order: third, second, first
divs[0].parentNode.appendChild(divs[0].parentNode.replaceChild(divs[2], divs[0]));