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:
- Tracking Sub Domains with Google Analytics
- Google Webmaster Guidelines
- WordPress Gears
- Using conditional comments to target Outlook 2007 - Campaign Monitor Blog
- ~jk typesafe objects in PHP
Want to buy a cheap laptop for your design work? read laptop reviews at laptopical.com