How to swap DOM child nodes in JavaScript?
What is the easiest way to swap the order of child nodes? For example I want childNode[3] to be childNode[4] and vice-versa. There is no need for cloning. You can just move one node before the other with this: childNode[4].parentNode.insertBefore(childNode[4], childNode[3]); You get the parent of the node. You then call the insertBefore method on the parent and you pass it the childNode[4] node and tell it you want it inserted before childNode[3]. That will give you the result of swapping their order so 4 will be before 3 when it's done. Reference documentation on insertBefore . Any node that