Skip to content

Instantly share code, notes, and snippets.

@cowboy
Created June 24, 2010 19:54
Show Gist options
  • Save cowboy/451887 to your computer and use it in GitHub Desktop.
Save cowboy/451887 to your computer and use it in GitHub Desktop.
jQuery outerHTML plugin
/*!
* jQuery outerHTML - v0.3 - 06/25/2010
* http://benalman.com/
*
* Copyright (c) 2010 "Cowboy" Ben Alman
* Dual licensed under the MIT and GPL licenses.
* http://benalman.com/about/license/
*
* Inspired by Brandon Aaron's outerHTML plugin.
* http://github.com/brandonaaron/jquery-outerhtml
*/
(function($){
'$:nomunge'; // Used by YUI compressor.
var div = $('<div/>');
$.fn.outerHTML = function() {
var elem = this[0],
tmp;
return !elem ? null
: typeof ( tmp = elem.outerHTML ) === 'string' ? tmp
: div.html( this.eq(0).clone() ).html();
};
})(jQuery);
@cowboy
Copy link
Author

cowboy commented Jul 23, 2010

My changes have been merged into brandon's plugin, so use that instead of this gist!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment