Skip to content

Instantly share code, notes, and snippets.

@brenopolanski
Created January 21, 2015 18:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brenopolanski/750a453368bb0ef380ce to your computer and use it in GitHub Desktop.
Save brenopolanski/750a453368bb0ef380ce to your computer and use it in GitHub Desktop.
A jQuery plugin to retrieve the outerHTML of an element
/*! Copyright (c) 2006 Brandon Aaron (brandon.aaron@gmail.com || http://brandonaaron.net)
* Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
* and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
*/
(function($){
var div;
$.fn.outerHTML = function() {
var elem = this[0],
tmp;
return !elem ? null
: typeof ( tmp = elem.outerHTML ) === 'string' ? tmp
: ( div = div || $('<div/>') ).html( this.eq(0).clone() ).html();
};
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment