Bug Tracker

Opened 14 years ago

Closed 14 years ago

Last modified 8 years ago

#310 closed bug (fixed)

jQuery ~ operator bug (and fix)

Reported by: dave.methvin@… Owned by:
Priority: minor Milestone:
Component: core Version:
Keywords: Cc:
Blocked by: Blocking:

Description

The tilde operator is selecting the left-side element when I think it is only supposed to select the sibling elements following the one on the left side. For example, given this HTML:

<div>
  <div>one</div>
  <div id="test">two</div>
  <div>three</div>
</div>

The expression $("#test ~ div").text() returns "two three" instead of "three". Most people using this selector have an expression on the right side that doesn't match the left side, as does the jQuery test case, so the bug probably doesn't crop up often. This fix to jQuery.token also makes it a bit faster using Array.slice:

"~", function(a){
  var s = jQuery.sibling(a);
  return s.n > 0 ? s.slice(s.n+1) : [];
}

Change History (2)

comment:1 Changed 14 years ago by anonymous

Note: the test "s.n > 0" does not seem right: it causes jQuery to return an empty list if the left side element is the first element; in the example above, remove <div>one</div> and you'll see the problem.

comment:2 Changed 14 years ago by brandon

Resolution: fixed
Status: newclosed

This is now fixed in SVN Rev: 585

See also #395

Note: See TracTickets for help on using tickets.