Skip to content

Instantly share code, notes, and snippets.

@gkiely
Last active December 18, 2015 21:29
Show Gist options
  • Save gkiely/5847359 to your computer and use it in GitHub Desktop.
Save gkiely/5847359 to your computer and use it in GitHub Desktop.
Swap elements
function swapElements(elm1, elm2) {
var parent1, next1,
parent2, next2;
parent1 = elm1.parentNode;
next1 = elm1.nextSibling;
parent2 = elm2.parentNode;
next2 = elm2.nextSibling;
parent1.insertBefore(elm2, next1);
parent2.insertBefore(elm1, next2);
}
//* pass in node elements
eg) jquery
swapElements($('.test')[0], $('test2')[0]);
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment