Skip to content

Instantly share code, notes, and snippets.

@ericpedia
Forked from etienned/changeElementType.js
Last active August 29, 2015 14:09
Show Gist options
  • Save ericpedia/9d01233a0f0ac08a1862 to your computer and use it in GitHub Desktop.
Save ericpedia/9d01233a0f0ac08a1862 to your computer and use it in GitHub Desktop.
Make it chainable
(function($) {
$.fn.changeElementType = function(newType) {
return this.each(function() {
var attrs = {};
$.each(this.attributes, function(idx, attr) {
attrs[attr.nodeName] = attr.nodeValue;
});
$(this).replaceWith(function() {
return $("<" + newType + "/>", attrs).append($(this).contents());
});
});
};
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment