Skip to main content

Bug Tracker

Side navigation

#7066 closed enhancement (wontfix)

Opened September 22, 2010 09:59PM UTC

Closed October 03, 2010 02:11AM UTC

More streamlined technique of appending a list

Reported by: davehamptonusa Owned by:
Priority: undecided Milestone: 1.4.3
Component: manipulation Version: 1.4.2
Keywords: Cc:
Blocked by: Blocking:

Currently, you can append a list of $objects or html like this:

Lets assume:

bar2 = $('<div>helo there</div>');

bar3 = $('<div/>', { text: 'text3'});

bar4 = $('<div/>', { text: 'text4'});

bar5 = $('<div/>', { text: 'text5'});

foo = [bar2, bar3, bar4, bar5];

body = $('body');

body.append(bar2, bar3, bar4, bar5);

Arguably, this is cumbersome and requires some contortions in certain situations.

You can also do this:

body.append.apply(body, $.isArray(foo) ? foo : [foo]);

This is also somewhat counterintuitive.

It would be more convenient if you could do this:


This currently fails, but could be allowed if jquery.clean were altered to include

if ( jQuery.isArray( elems[0] ) ) {

elems = elems[0];


after the var declaration. This would stay backward compatible with the apply technique.

I ran the test suite against this and it appeared to function normally, although honestly, I know I wasn't running it correctly.

Why the change? First its nice sugar.

Second, in use its faster than looping over an append(which many people do).

Why say no?

Maybe you have plans for some way cooler use for an array.

It does add an additional check to every call to clean - so it slows a few things down.

Attachments (0)
Change History (2)

Changed September 23, 2010 01:27AM UTC by snover comment:1

priority: → undecided

And how much faster is this than simply putting the elements themselves into the array by [ bar2[0], bar3[0], bar4[0], bar5[0] ] and then appending the array?

Changed October 03, 2010 02:11AM UTC by snover comment:2

resolution: → wontfix
status: newclosed