Created
July 24, 2011 01:18
-
-
Save peterjwest/1102076 to your computer and use it in GitHub Desktop.
Better outerHtml plugin
This file contains 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
(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