Created
June 18, 2012 23:57
-
-
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
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
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 { | |
originalAppend.call(this, 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]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks! Very small piece of code for something that should definitely be in jQuery.