Swapping nodes in a DOM tree
by Pascal Opitz on April 12 2007, 09:34
I was quite surprised to find out that the insertBefore method actually does most of the job for you.
A detail in the manual offers us insight in how: "If the newChild is already in the tree, it is first removed."
Hence:
myNode.parentNode.insertBefore(myNode, myNode.nextSibling);
Comments
That is actually quite nice to know. Is it implemented correctly in all the usual PHP, JS, different browsers whatever? And when can I add Ruby (on, over, under or without Rails) to that list?
by Matthias on April 13 2007, 13:46 #