Skip to content

Instantly share code, notes, and snippets.

@peterjwest
Created July 24, 2011 01:18
Show Gist options
  • Save peterjwest/1102076 to your computer and use it in GitHub Desktop.
Save peterjwest/1102076 to your computer and use it in GitHub Desktop.
Better outerHtml plugin
(function($){
$.fn.outerHtml = function() {
if (this.length == 0) return false;
var elem = this[0], name = elem.tagName.toLowerCase();
if (elem.outerHTML) return elem.outerHTML;
var attrs = $.map(elem.attributes, function(i) { return i.name+'="'+i.value+'"'; });
return "<"+name+(attrs.length > 0 ? " "+attrs.join(" ") : "")+">"+elem.innerHTML+"</"+name+">";
};
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment