Skip to content

Instantly share code, notes, and snippets.

Created June 18, 2012 23:57
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save marcuswestin/2951521 to your computer and use it in GitHub Desktop.
Monkey-patch jquery $('.foo').append(...) to accept variable number arguments and arrays of elements
var originalAppend = $.fn.append
$.fn.append = function() {
if (arguments.length == 1) {
var arg = arguments[0]
if ($.isArray(arg)) {
for (var i=0; i<arg.length; i++) { this.append(arg[i]) }
} else {, arg)
} else {
for (var i=0; i<arguments.length; i++) { this.append(arguments[i]) }
return this
// Now possible:
$('.foo').append('foo', 'bar', [1,2,3])
Copy link

malammar commented Aug 7, 2012

Thanks! Very small piece of code for something that should definitely be in jQuery.

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