Last active
September 15, 2015 09:27
-
-
Save fnnzzz/b1083a92a1f1359389b4 to your computer and use it in GitHub Desktop.
swap elements
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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