Bug Tracker

Opened 8 years ago

Closed 8 years ago

#7066 closed enhancement (wontfix)

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:

Description

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: body.append(foo);

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.

Change History (2)

comment:1 Changed 8 years ago by snover

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?

comment:2 Changed 8 years ago by snover

Resolution: wontfix
Status: newclosed
Note: See TracTickets for help on using tickets.