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:

Description

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 4.1.249.1064 unknown (45376)
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
  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);

  log('');

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

  alert(logstr);
});
</script>
</head>
<body>
  <table>
  <tbody>
  <tr><td>1</td></tr>
  <tr class="bottom"><td>x</td></tr>
  <tr><td>2</td></tr>
  <tr class="bottom"><td>y</td></tr>
  <tr><td>3</td></tr>
  <tr class="bottom"><td>z</td></tr>
  <tr><td>4</td></tr>
  </tbody>
  </table>
</body>
</html>

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.