Created
June 28, 2016 05:52
-
-
Save avishwakarma/f3e18ce8b0c11d02e5e3184e2adf4bca to your computer and use it in GitHub Desktop.
jQuery plugin to swap two elements to each other using $.replaceWith function
This file contains hidden or 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
| /** | |
| * $.swap - jQuery plugin to swap two elements | |
| * Swap the current element with other element | |
| * @uses $("#eample").swap($("#element")) | |
| */ | |
| $.fn.swap = function(to) { | |
| return this.each(function(){ | |
| var ct = $(to).clone(true); | |
| var cf = $(this).clone(true); | |
| $(to).replaceWith(cf); | |
| $(this).replaceWith(ct); | |
| }); | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment