Bug Tracker

Opened 15 years ago

Closed 15 years ago

Last modified 10 years ago

#310 closed bug (fixed)

jQuery ~ operator bug (and fix)

Reported by: [email protected] Owned by:
Priority: minor Milestone:
Component: core Version:
Keywords: Cc:
Blocked by: Blocking:


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 id="test">two</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 15 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 15 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.