Bug Tracker

Modify

Ticket #310 (closed bug: fixed)

Opened 7 years ago

Last modified 15 months ago

jQuery ~ operator bug (and fix)

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

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

comment:1 Changed 7 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 7 years ago by brandon

  • Status changed from new to closed
  • Resolution set to fixed

This is now fixed in SVN Rev: 585

See also #395

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.