Swapping nodes in a DOM tree
published 12 April 2007
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);
Comment
- haha, the manual.
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?
— Matthias Willerich 13 April, 7:46pm #
Quick links
Other people's articles that we think you might be interested in:
- Ajaxian » Web Inspector: Looking good, and profiling nicely
- smush it!
- cssdoc - Trac
- CSS Systems for writing maintainable CSS | Natalie Downe
- The PNG Gamma Dilemma - Trevor Morris Photographics
Want to buy a cheap laptop for your design work? read laptop reviews at laptopical.com