Skip to content

Instantly share code, notes, and snippets.

@mkormendy
Last active August 29, 2015 14:21
Show Gist options
  • Save mkormendy/c9de299b997d084d59ba to your computer and use it in GitHub Desktop.
Save mkormendy/c9de299b997d084d59ba to your computer and use it in GitHub Desktop.
simple jQuery plugin to replace an element type
(function($) {
$.fn.changeElementType = function(newType) {
var attrs = {};
$.each(this[0].attributes, function(idx, attr) {
attrs[attr.nodeName] = attr.nodeValue;
});
this.replaceWith(function() {
return $("<" + newType + "/>", attrs).append($(this).contents());
});
}
})(jQuery);
// use:
$("b").changeElementType("h1");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment