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:
- How To Use Valid XHTML Tags in TextMate
- 125 Social Bookmarking Sites : Importance of User Generated Tags, Votes and Links
- Email Standards Project
- Use Gmail to generate unlimited e-mail addresses
- A List Apart: Articles: Text-Resize Detection