Swap two nodes
The function below swaps two given nodes, nodeA and nodeB: const swap = function (nodeA, nodeB) { const parentA = nodeA.parentNode; const siblingA = nodeA.nextSibling === nodeB ? nodeA : nodeA.nextSibling; // Move `nodeA` to before the `nodeB` nodeB.parentNode.insertBefore(nodeA, nodeB); // Move `nodeB` to before the sibling of `nodeA` parentA.insertBefore(nodeB, siblingA); };
标签:nodeB,const,nodeA,javascript,two,Swap,nodes From: https://www.cnblogs.com/wingxyz/p/16856405.html