Bug Tracker

Modify

Ticket #9055 (closed bug: wontfix)

Opened 2 years ago

Last modified 15 months ago

.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:
Blocking: Blocked by:

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

Change History

comment:1 Changed 2 years ago by timmywil

  • Priority changed from undecided to high
  • Status changed from new to open
  • Component changed from unfiled to traversing

comment:2 Changed 2 years ago by ajpiano

  • Status changed from open to closed
  • Resolution set to wontfix

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.

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.