Skip to content

Instantly share code, notes, and snippets.

@fnnzzz
Last active September 15, 2015 09:27
Show Gist options
  • Save fnnzzz/b1083a92a1f1359389b4 to your computer and use it in GitHub Desktop.
Save fnnzzz/b1083a92a1f1359389b4 to your computer and use it in GitHub Desktop.
swap elements
jQuery.fn.swapWith = function(to) {
return this.each(function() {
var copy_to = $(to).clone(true);
var copy_from = $(this).clone(true);
$(to).replaceWith(copy_from);
$(this).replaceWith(copy_to);
});
};
$(selector1).swapWith(selector2);
/* jQuery.fn.swapWith = function(to) {
return this.each(function() {
var copy_to = $(to).clone(true);
$(to).replaceWith(this);
$(this).replaceWith(copy_to);
});
}; */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment