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) : []; }
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.