Skip to content

Instantly share code, notes, and snippets.

@JDMcKinstry
Last active July 2, 2016 22:39
Show Gist options
  • Save JDMcKinstry/ce699e82c7e07d02bae82e642fb4275f to your computer and use it in GitHub Desktop.
Save JDMcKinstry/ce699e82c7e07d02bae82e642fb4275f to your computer and use it in GitHub Desktop.
Simply adds outerHTML method to jQuery
;(function($) {
$.extend({
outerHTML: function() {
var $ele = arguments[0],
args = Array.prototype.slice.call(arguments, 1)
if ($ele && !($ele instanceof jQuery) && (typeof $ele == 'string' || $ele instanceof HTMLCollection || $ele instanceof Array)) $ele = $($ele);
if ($ele && $ele.length) {
if ($ele.length == 1) return $ele[0].outerHTML;
else return $.map($("div"), function(ele,i) { return ele.outerHTML; });
}
throw new Error("Invalid Selector");
}
})
$.fn.extend({
outerHTML: function() {
var args = [this];
if (arguments.length) for (x in arguments) args.push(arguments[x]);
return $.outerHTML.apply($, args);
}
});
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment