Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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