Skip to main content

Bug Tracker

Side navigation

#9055 closed bug (wontfix)

Opened May 03, 2011 07:02AM UTC

Closed May 03, 2011 04:41PM UTC

Last modified March 14, 2012 05:01AM UTC

.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:
Description

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

Attachments (0)
Change History (2)

Changed May 03, 2011 01:59PM UTC by timmywil comment:1

component: unfiledtraversing
priority: undecidedhigh
status: newopen

Changed May 03, 2011 04:41PM UTC by ajpiano comment:2

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 ) 

http://jsfiddle.net/uYXQz/1/

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.