Bug Tracker

Opened 12 years ago

Closed 12 years ago

Last modified 11 years ago

#9055 closed bug (wontfix)

.add fails on an empty jQuery object

Reported by: ealexs Owned by:
Priority: high Milestone: 1.next
Component: traversing Version: 1.5.2
Keywords: Cc:
Blocked by: Blocking:


This is very simple, I create an empty jQuery object and I add DOM elements to it. In the end the .length is zero Works fine if i create a JS array with the same elements and add them like this: jQuery(some_list)

Let me give you the example:

jQuery(document).ready( function () { var coll = jQuery();

coll.add( document.getElementById("t1") ); coll.add( document.getElementById("t2") ); coll.add( document.getElementById("t3") );

alert(coll.length); });

coll.length = 0

PS: tested with v. 1.5.2 and 1.5.0

Thanks, Alex

Change History (2)

comment:1 Changed 12 years ago by timmywil

Component: unfiledtraversing
Priority: undecidedhigh
Status: newopen

comment:2 Changed 12 years ago by ajpiano

Resolution: wontfix
Status: openclosed

This is not a bug, it's the way .add has always worked. .add does *not* mutate the original set, it returns a new set. If you want to save the result into the original variable, you have to use an assignment.

coll = coll.add( foo ) 


This hit me once and comes up regularly, I even listed it as a caveat to be aware of on Fixing These jQuery. But is it something that we plan to fix, changing the behaviour of add all over the place? I don't think so, so I'm gonna close this wontfix for now.

Note: See TracTickets for help on using tickets.