Skip to content

Instantly share code, notes, and snippets.

@avisek
Created October 7, 2018 18:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save avisek/b0f0c7c267fa79b612679054164ee49e to your computer and use it in GitHub Desktop.
Save avisek/b0f0c7c267fa79b612679054164ee49e to your computer and use it in GitHub Desktop.
function swapDomNodes(a, b) {
var afterA = a.nextSibling;
if (afterA == b) {
swapDomNodes(b, a);
return;
}
var aParent = a.parentNode;
b.parentNode.replaceChild(a, b);
aParent.insertBefore(b, afterA);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment