Last active
July 2, 2016 22:39
-
-
Save JDMcKinstry/ce699e82c7e07d02bae82e642fb4275f to your computer and use it in GitHub Desktop.
Simply adds outerHTML method to jQuery
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($) { | |
$.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