Swap DOM nodes

To swap DOM nodes you can use this example:


var oldNodeAtPosition = document.getElementById(existingNode);
var newNodeAtPosition = document.getElementById(retrievedNode);
// swap DOM nodes
// API: replaceChild(child1,child2) -- replace node child2 by node child1
oldNodeAtPosition.parentNode.replaceChild(newNodeAtPosition.cloneNode(true), oldNodeAtPosition);
newNodeAtPosition.parentNode.replaceChild(oldNodeAtPosition.cloneNode(true), newNodeAtPosition);

Comments

Popular posts from this blog

Using Trello and Confluence to manage UX design project. Part 2

How do I use InVision

Using Trello and Confluence to manage UX design project. Part 1