Skip to content

Instantly share code, notes, and snippets.

@avishwakarma
Created June 28, 2016 05:52
Show Gist options
  • Select an option

  • Save avishwakarma/f3e18ce8b0c11d02e5e3184e2adf4bca to your computer and use it in GitHub Desktop.

Select an option

Save avishwakarma/f3e18ce8b0c11d02e5e3184e2adf4bca to your computer and use it in GitHub Desktop.
jQuery plugin to swap two elements to each other using $.replaceWith function
/**
* $.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