Skip to main content

Bug Tracker

Side navigation

#310 closed bug (fixed)

Opened October 24, 2006 02:58PM UTC

Closed November 15, 2006 03:53PM UTC

Last modified March 14, 2012 09:08PM UTC

jQuery ~ operator bug (and fix)

Reported by: dave.methvin@gmail.c 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) : [];
}
Attachments (0)
Change History (2)

Changed November 09, 2006 06:03AM UTC by anonymous comment:1

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.

Changed November 15, 2006 03:53PM UTC by brandon comment:2

resolution: → fixed
status: newclosed

This is now fixed in SVN Rev: 585

See also #395