Bug Tracker

Opened 13 years ago

Closed 13 years ago

#6626 closed bug (invalid)

not() and filter() not behaving correctly when used with $(array)

Reported by: tafandi Owned by:
Priority: Milestone: 1.4.3
Component: traversing Version: 1.4.2
Keywords: Cc:
Blocked by: Blocking:


If we create a jQuery object from an array, and then apply not() and filter() on that object, the result won't be correct.

The following code is used for testing. The top part (using selector, ie. $('tr') is the control showing the correct result as a comparison). The bottom part (creating an array and then creating a jQuery object based on them) is the incorrect result demonstrating this bug.

The test is done on:

  • FF 3.6.3
  • IE 8.0.6001.18702
  • Chrome unknown (45376)
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<script type="text/javascript">
  var logstr = '';
  function log(s) { logstr += s + '\n'; }

  function test(s, o) {
    with (o) {
      log(s + ' length: ' + length);  
      log(s + ' not(".bottom"): ' + not('.bottom').length);  
      log(s + ' filter(".bottom"): ' + filter('.bottom').length);  
      log(s + ' not("tr.bottom"): ' + not('tr.bottom').length);  
      log(s + ' filter("tr.bottom"): ' + filter('tr.bottom').length);  

  var tr = $('tr');
  test('selector', tr);


  var rows = new Array(), i = 0;
  tr.each(function() { rows[i] = $(this); i++; });
  test('array', $(rows));

  <tr class="bottom"><td>x</td></tr>
  <tr class="bottom"><td>y</td></tr>
  <tr class="bottom"><td>z</td></tr>

Attachments (1)

bug_6626_output.GIF (10.8 KB) - added by tafandi 13 years ago.
JS alert window displayed by the script above

Download all attachments as: .zip

Change History (2)

Changed 13 years ago by tafandi

Attachment: bug_6626_output.GIF added

JS alert window displayed by the script above

comment:1 Changed 13 years ago by dmethvin

Resolution: invalid
Status: newclosed

jQuery(array) accepts an array of DOM elements, not an array of jQuery objects.

Note: See TracTickets for help on using tickets.